mardi 3 novembre 2020

.NET Private Fields With Attributes Are Not Found In Inherited Classes [duplicate]

In my code i have:

  • Custom attribute applied to fields
  • A dictionary with the key type string and the value of SourceKeyField
  • SourceKeyField has a FieldInfo List
  • This essentially ties a field to a string key in a dictionary so when dictionary is changed the tied fields also will.

THE PROBLEM:

Private fields of a base class that are tied with this custom attribute are not picked up by Reflection while iterating through attributes.

The class order is like this:

  • MyEntity
  • BaseSourceEntity
  • SourceEntity

So if i was running the reflection code on MyEntity, the private fields with the custom attribute in BaseSourceEntity and SourceEntity are not found.

The Custom Attribute
Reflection Code To Get The Attribute

Example usage:

[DEFINE_KEYFIELD(SourceFieldTypes.FIELD_INTEGER, "spawnflags")] private int m_flags = 0;

WHAT I KNOW:
Type class has a thing called BaseType. But i am not exactly sure if it's fit for my situation or that i can make use of it at all.

Hopefully this is a simple issue and that it can be solved.





Aucun commentaire:

Enregistrer un commentaire