|
-
December 16th, 2010, 11:06 PM
#1
How to know if field returned by Type.GetFields() is from base class?
I have some code that uses one base class and about 100 (yes, really!) derived classes.
I wish to put into the base class some code that will serialize/deserialize any derived class. To do this I use reflection and get fields and values one at a time.
The problem I am having is that I am getting the fields for my derived class and my base class all at once.
For instance:
public class BaseClass
{
public int base_var;
}
public class A : BaseClass
{
public string a_string;
}
....
A instance_of_A= new A();
Type type = instance_of_A.GetType();
FieldInfo [] fi = type.GetFields();
foreach(FieldInfo f in fi)
{
... here I see both base_var and a_string...
... I want to be able to filter out the stuff in my base class and just deal with a_string etc.
...Is there a flag in FieldInfo that gives me this information?
}
If I want *only* the base stuff I can use a BindingFlag for a filter. But that is not what I want.
Eric
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|