Field Name

  • Thread starter Thread starter Ken Kast
  • Start date Start date
K

Ken Kast

I want to be able to determine to which field in a class a particular object
refers. In other words, I have (in C#)
class MyClass
{
private object myField;
}

x = new MyClass();
object y = new object();
x.myField = y;

I want to pass y into a method, which knows about MyClass, and have it
determine that y defines myField. I know that I can determine the names and
types of fields via reflection. Is there a way to match up field instances?

Ken
 
Ken Kast said:
I want to be able to determine to which field in a class a particular object
refers. In other words, I have (in C#)
class MyClass
{
private object myField;
}

x = new MyClass();
object y = new object();
x.myField = y;

I want to pass y into a method, which knows about MyClass, and have it
determine that y defines myField. I know that I can determine the names and
types of fields via reflection. Is there a way to match up field instances?

Well, you could fetch each value and check whether it's the same
reference as the one you passed in - but there may be ambiguity, in
that there may be more than one field with the same value.
 
Back
Top