I'm currently working on reflection with c# and I have a question. I try to invoke different class types which might be abstract or interface. So I just don't invoke the methods of those, because I cannot create an instance(obviously). But I'm not satisfied with this.
My question is: is it possible to work around this somehow and create an instance of something, where I can invoke the methods of the given abstract class type? Sorta like making a class that inherits from a Template which then can be the abstract type?
foreach (MethodInfo m in _classType.GetMethods(bindingFlags))
{
if (_classType.IsAbstract || _classType.IsInterface)
{
// only invoke instanciable types
MessageBox.Show("Abstract class and Interface cannot be invoked!");
}
else
{
var ms = CreateStringFromMethodForCheckedBox(m);
if (s == ms)
{
m.Invoke(Activator.CreateInstance(_classType), null);
}
}
}
Aucun commentaire:
Enregistrer un commentaire