Checking state of object field at runtime?

  • Thread starter Thread starter David Whitney
  • Start date Start date
D

David Whitney

All:

I've been working with some Reflection code to interrogate some
runtime object information, and was wondering the following...

Is there any call that can be made to determine whether a value type
(int, float, etc) of an object was initialized *only*, not set
programmatically?

I know there's no way to distinguish, for example, a default int value
of 0 from an assigned int value of 0, but I thought perhaps there
might be a buried state flag or field somewhere that might track when
a given field was "dirty" because it had been set (for whatever
reason).

Probably a grasp at straws, I realize, but I'm really trying to
overcome a run-tim value-type default problem...

Many thanks in advance,
David

Please reply to group; email is long since dead.
 
Because it is a valud type, there is no way.

When you declare it, you can set it to something like Int32.MinValue, for
integers, and then compare against that, since it is highly unlikly you will
actually be assigning the minimum value (or maybe impossible). That's about
it.
 
David Whitney said:
I've been working with some Reflection code to interrogate some
runtime object information, and was wondering the following...

Is there any call that can be made to determine whether a value type
(int, float, etc) of an object was initialized *only*, not set
programmatically?

I don't believe so. If you think about it, that would take an extra bit
per field per object - it would get expensive very quickly.
 
Marina/Jon:

Thanks for your replies!

I'm afraid I've come to the same conclusions you offered. I actually
opted to use the Int32.MaxValue option, which is essentially what
Marina suggested. That should do the trick. I just took a shot that
someone with more experience than I might know a secret to get around
the problem.

Again, many thanks!

-David
 
Back
Top