我正在尝试为GraphQL.NET创建一个通用映射函数。以下是我使用的示例枚举:
public enum ForcePower
{
Throw,
Pull,
Choke,
Lightning
}
public class Jedi
{
public string Id { get; set; }
public string Name { get; set; }
public string HomePlanet { get; set; }
public ForcePower Power { get; set; }
}
目前,必须明确传递枚举:
object obj = new Jedi();
PropertyInfo[] properties = obj.GetType().GetProperties();
foreach (var propertyInfo in properties)
{
var isEnum = propertyInfo.PropertyType.GetTypeInfo().BaseType == typeof(Enum);
if (isEnum)
{
var enumType = typeof(EnumerationGraphType<ForcePower>);
Field(type: enumType, name: propertyInfo.Name, description: description);
}
}
Can&#39; ForcePower&#39;动态传递?