[Mono-list] FieldInfo.GetValue trouble with null
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 - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] FieldInfo.GetValue trouble with null
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 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 - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] FieldInfo.GetValue trouble with null
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 - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] FieldInfo.GetValue trouble with null
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 - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list
Re: [Mono-list] FieldInfo.GetValue trouble with null
To answer Phil's original question: Should I not be expecting FieldInfo.GetValue to return uninitialized ints and bools as null? That's correct, you should not expect that behavior. There's no such thing as an uninitialized value. Everything is always initialized to 0, null, or the equivalent. -- - Joshua Tauberer http://taubz.for.net ** Nothing Unreal Exists ** ___ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list