Reflection - Difference between DateTime.MaxValue andDecimal.MaxValue

  • Thread starter Thread starter Joey Fontaine
  • Start date Start date
J

Joey Fontaine

I just noticed that, when using intellisense, the DateTime.MaxValue
field has a static property icon whereas the Decimal.MaxValue field
has a constant property icon. However, when looking at the
PropertyInfo data displayed by using reflection against the types, I
can see no inherent differences between the properties.

How does microsoft determind this difference? Or, how can I determine
the difference using reflection?
 
Joey said:
I just noticed that, when using intellisense, the DateTime.MaxValue
field has a static property icon whereas the Decimal.MaxValue field
has a constant property icon. However, when looking at the
PropertyInfo data displayed by using reflection against the types, I
can see no inherent differences between the properties.
Neither DateTime.MaxValue nor Decimal.MaxValue are properties, they're
fields (so I assume you're talking about FieldInfo). Both are public static
initonly fields.
How does microsoft determind this difference? Or, how can I determine
the difference using reflection?

This is a guess, but VS might be using the DecimalConstantAttribute
associated with the decimal field (but not the DateTime field). You can
verify this yourself by declaring

const decimal i = 0.0;
static readonly decimal i = 0.0;

These produce the same declarations except for the first one having an extra
attribute, and VS shows different icons.
 
Neither DateTime.MaxValue nor Decimal.MaxValue are properties, they're
fields (so I assume you're talking about FieldInfo). Both are public static
initonly fields.


This is a guess, but VS might be using the DecimalConstantAttribute
associated with the decimal field (but not the DateTime field). You can
verify this yourself by declaring

   const decimal i = 0.0;
   static readonly decimal i = 0.0;

These produce the same declarations except for the first one having an extra
attribute, and VS shows different icons.

Just to follow up on Jeroen's post; One can use the IsLiteral and
IsStatic properties of the FieldInfo class along with the
CustomConstantAttribute, DecimalConstantAttribute and
DateTimeConstantAttribute located in the
System.Runtime.CompilerServices namespace in order to determine if a
FieldInfo object is a constant.

Thanks!
 
Back
Top