我对 System.Reflection 有点问题。请看附件代码:
class Program
{
public static FieldInfo[] ReflectionMethod(object obj)
{
var flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
return obj.GetType().GetFields(flags);
}
static void Main()
{
var test = new Test() { Id = 0, Age = 12, Height = 24, IsSomething = true, Name = "Greg", Weight = 100 };
var res = ReflectionMethod(test);
}
}
public class Test
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public bool IsSomething { get; set; }
public int Weight { get; set; }
public int Height { get; set; }
public int CalculationResult => Weight * Height;
public Test()
{
}
}
似乎 getfields 方法没有获取计算的属性 CalculationResult。我假设我需要使用另一个标志,但我不知道它是哪一个。
在此先感谢,如有必要,我会很乐意提供更多信息。