G
Guest
I am using reflection and trying to determine if an assembly contains a type
that has a particular interface. So my code looks like this:
Assembly assembly = Assembly.LoadFile(fileName);
foreach (Module module in assembly.GetModules())
{
foreach (Type type in module.GetTypes())
{
try
{
object instance = Activator.CreateInstance(type);
if (instance is IMyInterface)
{
.. Do Something
}
}
catch
{
}
}
}
However, I would prefer not to have call CreateInstance then check the
object returned to see if it supports the interface. Is there anyway to
check the "Type" to see if it supports the interface without having to call
CreateInstance?
-Wayne
that has a particular interface. So my code looks like this:
Assembly assembly = Assembly.LoadFile(fileName);
foreach (Module module in assembly.GetModules())
{
foreach (Type type in module.GetTypes())
{
try
{
object instance = Activator.CreateInstance(type);
if (instance is IMyInterface)
{
.. Do Something
}
}
catch
{
}
}
}
However, I would prefer not to have call CreateInstance then check the
object returned to see if it supports the interface. Is there anyway to
check the "Type" to see if it supports the interface without having to call
CreateInstance?
-Wayne