Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Reflection - Difference between DateTime.MaxValue andDecimal.MaxValue

Reply
 
Old 10-13-2008   #1 (permalink)
Joey Fontaine


 
 

Reflection - Difference between DateTime.MaxValue andDecimal.MaxValue

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?

My System SpecsSystem Spec
Old 10-13-2008   #2 (permalink)
Jeroen Mostert


 
 

Re: Reflection - Difference between DateTime.MaxValue and Decimal.MaxValue

Joey Fontaine wrote:
Quote:

> 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.
Quote:

> 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.

--
J.
My System SpecsSystem Spec
Old 12-04-2008   #3 (permalink)
Joey Fontaine


 
 

Re: Reflection - Difference between DateTime.MaxValue andDecimal.MaxValue

On Oct 13, 1:08*pm, Jeroen Mostert <jmost...@xxxxxx> wrote:
Quote:

> Joey Fontaine wrote:
Quote:

> > 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.
>
Quote:

> > 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.
>
> --
> J.
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!
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Question on Reflection .NET General
Rounding of a [datetime] PowerShell
bug in string<->datetime conversion? PowerShell
How to use [datetime]::now properly? PowerShell
RC2 DateTime casting PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46