Mögliche Duplizieren:
Type.GetFields() - only returning “public const” fieldsReflecting konstante Eigenschaften/Felder in .net
Ich habe eine Klasse, die wie folgt aussieht wie folgt:
public class MyConstants
{
public const int ONE = 1;
public const int TWO = 2;
Type thisObject;
public MyConstants()
{
thisObject = this.GetType();
}
public void EnumerateConstants()
{
PropertyInfo[] thisObjectProperties = thisObject.GetProperties(BindingFlags.Public);
foreach (PropertyInfo info in thisObjectProperties)
{
//need code to find out of the property is a constant
}
}
}
Bascially wird es versuchen, reflektieren selbst. Ich weiß, wie man Felder EINS, & ZWEI widerspiegelt. Aber woher weiß ich, ob es eine Konstante ist oder nicht?
Effektiv betrügen von http://StackOverflow.com/Questions/1287797 –
Ich nehme das zurück ... Ich kann die Felder ONE & TWO nicht finden. – deostroll
Sie sind nicht nur Felder, sie sind statische Felder, keine Instanzfelder. –