I have a class and interface set up like this:
public partial interface INav_Item
{
[FieldID("df918977-369c-4a06-ac38-adb8741b5f75")]
string Title {get; set;}
}
public partial class Nav_Item : INav_Item
{
[FieldID("df918977-369c-4a06-ac38-adb8741b5f75")]
public virtual string Title {get; set;}
}
And then I have this class inherited:
public class MenuItem : Nav_Item
{
public virtual IEnumerable<MenuItem> Children { get; set; }
//some other properties
}
I'm now trying to instantiate an object of type MenuItem
, and trying to get the attributes from the Inherited class (I can't instantiate MenuItem
directly, because the type is being passed in from other classes)
object obj = Activator.CreateInstance(type);
foreach (PropertyInfo propInfo in type.GetProperties())
{
FieldAttribute sfi =(FieldAttribute)propInfo.PropertyType.GetCustomAttribute(typeof(FieldAttribute));
}
But this is giving me sfi
to be null
. I've also debugged to try getting all the attributes:
propInfo.PropertyType.GetCustomAttributes()
.. but this is only giving me the system attributes (type and something else), but my own attributes are just not there? Is this is because the class is inherited? How can I get the attribute value?
EDIT:
The attribute class is defined as this:
public class FieldIDAttribute : Attribute
{
private string _id;
public FieldAttribute(string Id)
{
_id = Id;
}
public ID TheFieldID
{
get
{
return new ID(_id);
}
}
}
Aucun commentaire:
Enregistrer un commentaire