how to use the a interface declared in a dll
-
there are interfaces declared in a dll below -------------------- Encrypt.dll ------------------------- interface IDESCoder { string CreateCode(string IVString,string KeyString,string StringToEncode); string GetCode(string IVString, string KeyString, string StringToDecode); } interface IMD5Encoder { string CreateCode(string StringToEncode); } public class ClsDES : IDESCoder { public string CreateCode(string IVString, string KeyString, string StringToEncode) { } public string GetCode(string IVString, string KeyString, string StringToDecode) { } private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode) { } } public class CldMD5 : IMD5Encoder { public string CreateCode(string StringToEncode) { } } ----------------------------------------------------------------------- and there is a Host -------------------- test.exe ---------------------------------------- string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllType = myDllAssembly.GetType("IDESCoder"); if (dllType!=null) { ......?????? } ------------------------------------------------------------------------- then,what should i do next with Reflection if i want to use Interface declared in the dll??
-
there are interfaces declared in a dll below -------------------- Encrypt.dll ------------------------- interface IDESCoder { string CreateCode(string IVString,string KeyString,string StringToEncode); string GetCode(string IVString, string KeyString, string StringToDecode); } interface IMD5Encoder { string CreateCode(string StringToEncode); } public class ClsDES : IDESCoder { public string CreateCode(string IVString, string KeyString, string StringToEncode) { } public string GetCode(string IVString, string KeyString, string StringToDecode) { } private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode) { } } public class CldMD5 : IMD5Encoder { public string CreateCode(string StringToEncode) { } } ----------------------------------------------------------------------- and there is a Host -------------------- test.exe ---------------------------------------- string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllType = myDllAssembly.GetType("IDESCoder"); if (dllType!=null) { ......?????? } ------------------------------------------------------------------------- then,what should i do next with Reflection if i want to use Interface declared in the dll??
string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question if (dllType!=null) { //TODO---you can use Factory pattern to improve it dllTypeInterface interf=Activator.CreateInstance(dllTypeClass ); } and you can choose another simpler way to resolve the problem. first of all,You should Add references into your application in VS.NET. then you can use it like using some interface or class in mscorlib.dll. for example. using System.Int32;
It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.
-
string filepath = @"E:\Encrypt.dll"; Assembly myDllAssembly = Assembly.LoadFrom(filepath); Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question if (dllType!=null) { //TODO---you can use Factory pattern to improve it dllTypeInterface interf=Activator.CreateInstance(dllTypeClass ); } and you can choose another simpler way to resolve the problem. first of all,You should Add references into your application in VS.NET. then you can use it like using some interface or class in mscorlib.dll. for example. using System.Int32;
It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.