I am using reflection to get all my modifier types from the assembly and I put them in a dictionary.
I want to see what content a modifier takes. Each NodeContent has interfaces to match them to the modifier. Each modifier has a abstract property GetContentType wich returns a interface type to show what content it can take.
But it forces me to create a object of the type to use PropertyInfo.GetValue(), wich defies what I am trying to do because I don't know what content type it takes.
I assume I could just get the first constructor and the first parameter but that to me doesn't feel very safe.
So my question is. Is there another way to get PropertyInfo.GetValue() without using a object but just a type?
public static Dictionary<string, Type> GetFittingModifiers(NodeContent content)
{
Dictionary<string, Type> fits = new Dictionary<string, Type>();
foreach(KeyValuePair<string,Type> modifierType in modifiers)
{
PropertyInfo propertyInfo = modifierType.Value.GetProperty("GetContentType");
Modifier modifier = //make object of modifierType.Value without knowing what the constructor takes
Type contentType = (Type)propertyInfo.GetValue(modifier, null);
if (HasInterface(content, contentType))
fits.Add(modifierType.Key, modifierType.Value);
}
return fits;
}
Aucun commentaire:
Enregistrer un commentaire