[Mono-list] FieldInfo.GetValue trouble with null

Ben Maurer bmaurer@users.sourceforge.net
Sun, 04 Apr 2004 17:11:38 -0400


Yes they will. For an object, you will get a null pointer.
for a value type, you get a pointer to a boxed instance of the default
value for that object.


On Sun, 2004-04-04 at 16:55, Met wrote:
> Hello,
> 
> On Sun, 2004-04-04 at 16:16, Ben Maurer wrote:
> > For valuetypes, the `null' value is 0, false, or whatever (basically,
> > what happens if each integer is set to 0 and each reference to null).
> > 
> > -- Ben
> 
> The problem with this is that it no longer equals the original object. 
> For example, if you instantiate an object, and then copy it via
> reflection (FieldInfo etc), they will not be copies of each other.  A 0
> will not equal an uninitialized null etc.
> 
> Should this be the way it is?  If so, how can you via reflection get the
> _real_ value of a Field?
> 
> ~ Matthew
> 
> > 
> > On Sun, 2004-04-04 at 14:42, Philip wrote:
> > > Question regarding the use of the FieldInfo object.
> > > I'm using the FieldInfo object, calling the GetValue(object) method. The
> > > object that I'm passing to the method is only partially populated, so
> > > some of the fields are uninitialized (null). However when the
> > > FieldInfo.GetValue(object) returns the value, uninitialized integers
> > > (which I had hoped would still be null) are returned as 0 and
> > > uninitialized bools (which should be null also) are returned as false,
> > > null strings however are returned properly. Has anyone else run into a
> > > similar problem? Should I not be expecting FieldInfo.GetValue to return
> > > uninitialized ints and bools as null? Any help would be great.
> > > 
> > > - Phil
> > > 
> > > _______________________________________________
> > > Mono-list maillist  -  Mono-list@lists.ximian.com
> > > http://lists.ximian.com/mailman/listinfo/mono-list
> > 
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list