net 遍历类中的变量
public TestClass
public const string a = "01101"
public const string c = "01101"
public const string d = "01101"
public const string e = "01101"
public const string f = "01101"
end Class
这只是一个例子。我想遍历TestClass中的这些常量。但没有什么办法。高手帮忙啊,谢了。
[解决办法]
var type=typeof(TestClass);
var consts=type.GetFields(BindingFlags.Static)//这边是获取静态字段 const也算
[解决办法]
反射GetFields
[解决办法]
BindingFlags BindingFlag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;Type type = typeof(TestClass);ropertyInfo[] properties = type.GetProperties(BindingFlag); //Dictionary<string, PropertyInfo> propertyColumnMapping = new Dictionary<string, PropertyInfo>(properties.Length); foreach (PropertyInfo p in properties) { // }