Say I have an Interface like this in a project called \"Interface\":
public interface TestInterface
{
string Operation();
}
and class which
Is there any way to access the methods via Interface only
Yes, there is. You can dynamically load an assembly with TestClass
without referencing it, create its instance via Activator.CreateInstance
and cast it to interface type:
var assembly = Assembly.Load(...);
var typeFromAssembly = assembly.GetTypes()...;
var myInterfaceVar = (TestInterface)Activator.CreateInstance(typeFromAssembly);
...or... you may use one of existing DI-frameworks (e.g. MEF) and do the same thing more right way:
[Import]
private TestInterface myInterfaceField;
or:
var myInterfaceVar = compositionContainer.GetExportedValue();
Depending of the way you prefer, you may ask more concrete question.