jeudi 10 mars 2016

GetCustomAttribute always returns null

I have an attribute class

 [AttributeUsage(AttributeTargets.Class)]
public class WizardAttribute : Attribute
{
    public bool AddGuid { get; set; }

    public WizardAttribute()
    {
    }

}

I'm trying to get this attribute via reflection like this

                    Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "bin\\some.dll");
                Type[] types = assembly.GetTypes();
                foreach (Type tt in types)
                {
                    if (tt.Name == "Somecontroller")
                    {
                        WizardAttribute attribute = (WizardAttribute)(tt.GetCustomAttribute(typeof(WizardAttribute)));
                    }
                }

and attributes always null

Please help





Aucun commentaire:

Enregistrer un commentaire