我尝试在我的 Car 类中获取有关常量的信息,但不幸的是,结果我只得到 4 个字段(名称、currentSpeed、maxSpeed、state)。我怎样才能得到字段常量。
谢谢。
public abstract class Car
{
protected string name;
protected short currentSpeed;
protected short maxSpeed;
protected EngineState state;
protected const int const = 1;
}
..................................................... ……
Type type = assembly.GetType("CarLibrary.Car");
MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
foreach (MemberInfo element in members)
Console.WriteLine("{0,-15}: {1}", element.MemberType, element);