After many fruitless searches I can't find the solution.
I want to do something like this Object obj = memberInfo.GetInstance();
Here is the method:
public static void DefineControl(Window currentForm, Role role)
{
foreach (MemberInfo member in currentForm.GetType().GetMembers())
{
Attribute ? attribute = member.GetCustomAttribute<AccessCategory>();
if (attribute != null)
{
bool authorized = ((AccessCategory)attribute).Authorized(role.Categories.ToArray());
if (!authorized)
{
Type type = currentForm.GetType();
FieldInfo field = type.GetField(member.Name);
Control control = (Control)field.GetValue(member); // control is null <- problem here
control.IsEnabled = false;
}
}
}
}
I can't get the instance of member
Thank you for your help!
A.
As it's a property, you will have to use
PropertyInfo
instead ofFieldInfo
A rough solution..