value equality

M

Marcel Sottnik

Hallo NG

Does anyone have an idea how could one implement, a general routine for
value equality ?
I mean something using Reflections to get all the members of a class and
compare them recursivelly until the comparison of value type is reached. I
found in Reflections only getting of public members. Although the internal
state of an object should not be interesting for evalution of equality I
would like to make a value equality check also with values at least
protected members...

Thx for any input
 
N

Nicholas Paldino [.NET/C# MVP]

Marcel,

You can definitely use reflection to do this, but at the same time, I
don't think it is a good idea. Value equality is difficult to standardize
depending on the nature of the definition of the object (and how it relates
to what it is representing).

If you still want to go with it though, you can reflect on protected,
private, and internal members using the NonPublic value from the
BindingFlags enumeration. Usually, most overloads of the methods you use to
get fields, properties, methods, etc, etc will take a group of values from
the BindingFlags enumeration to indicate what to reflect on.

Hope this helps.
 
M

Marcel Sottnik

Thanks Nicholas, you helped me.

Nicholas Paldino said:
Marcel,

You can definitely use reflection to do this, but at the same time, I
don't think it is a good idea. Value equality is difficult to standardize
depending on the nature of the definition of the object (and how it relates
to what it is representing).

If you still want to go with it though, you can reflect on protected,
private, and internal members using the NonPublic value from the
BindingFlags enumeration. Usually, most overloads of the methods you use to
get fields, properties, methods, etc, etc will take a group of values from
the BindingFlags enumeration to indicate what to reflect on.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Marcel Sottnik said:
Hallo NG

Does anyone have an idea how could one implement, a general routine for
value equality ?
I mean something using Reflections to get all the members of a class and
compare them recursivelly until the comparison of value type is reached. I
found in Reflections only getting of public members. Although the internal
state of an object should not be interesting for evalution of equality I
would like to make a value equality check also with values at least
protected members...

Thx for any input
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top