संभव डुप्लिकेट:
Type.GetFields() - only returning “public const” fieldsको दर्शाते हुए लगातार गुण/.net में खेतों
मैं एक वर्ग है जो इस प्रकार की तरह लग रहा है:
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 यह कोशिश कर रहा है को प्रतिबिंबित करने के अपने आप। मुझे पता है कि फील्ड वन, & TWO को कैसे प्रतिबिंबित किया जाए। लेकिन मुझे कैसे पता चलेगा कि यह स्थिर है या नहीं?
प्रभावी रूप से http://stackoverflow.com/questions/1287797 –
का डुप्लिकेट मैं इसे वापस लेता हूं ... मुझे फ़ील्ड एक और दो नहीं मिल रहा है। – deostroll
वे सिर्फ फ़ील्ड नहीं हैं, वे स्थिर फ़ील्ड हैं, उदाहरण फ़ील्ड नहीं। –