Possible en double:
Type.GetFields() - only returning “public const” fieldsdes propriétés réfléchissantes constantes/champs .net
J'ai une classe qui ressemble comme suit:
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 il tente de réfléchir lui-même. Je sais comment refléter les champs UN, & DEUX. Mais comment savoir si c'est une constante ou non?
Effectivement dupe de http://stackoverflow.com/questions/1287797 –
Je prends ça en arrière ... Je ne trouve pas les champs UN et DEUX. – deostroll
Ce ne sont pas seulement des champs, ce sont des champs statiques, pas des champs d'instance. –