Note that there are some explanatory texts on larger screens.

plurals
  1. PONot getting fields from GetType().GetFields with BindingFlag.Default
    primarykey
    data
    text
    <p>I am using the Reflection classes in order to get all the fields inside a certain object. My problem however is that it works perfectly when the fields are inside a normal class, like:</p> <pre><code>class test { string test1 = string.Empty; string test2 = string.Empty; } </code></pre> <p>Here i get both test1 and test2, my problem is that i use abstraction and thus several classes combined.</p> <p>I got something like:</p> <pre><code>class test3 : test2 { string test4 = string.Empty; string test5 = string.Empty; } class test2 : test1 { string test2 = string.Empty; string test3 = string.Empty; } class test1 { string test0 = string.Empty; string test1 = string.Empty; } </code></pre> <p>But when I run it, I don't get the fields back from the <code>GetType().GetFields(BindingFlag.Default)</code>.</p> <p>Everyone of those fields also have a property, <code>get; set;</code> attached to it. When I run the code, I get the properties all the way back to test1 but not the actual fields.</p> <p>This is the code that I'm trying to get the fields with:</p> <pre><code>FieldInfo[] fields = Obj.GetType().GetFields(BindingFlags.Default); foreach (FieldInfo field in fields) </code></pre> <p>I have also tried:</p> <pre><code>FieldInfo[] fields = Obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static); </code></pre> <p>I use the same code for the properties:</p> <pre><code>PropertyInfo[] properties = Obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static); foreach (PropertyInfo property in properties) </code></pre> <p>Any ideas why I get the properties from the abstracted classes but not the fields?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload