wim sturkenboom
Well-known member
Morning ( ) all,
I'm busy with an application and while coding I can see that it can be useful to convert part (one class) of that application at a later stage to a DLL (no experience with creating DLLs, but that is not part of the question).
Below code is part of the class that I consider to move to a DLL
This is the code that will stay in the application or needs to be coded in future applications that use the DLL
The idea is that from the DLL user defined methods in a specific class in the application that uses the DLL (that are not known when the DLL is compiled) can be called. So the programmer that uses the DLL will implement the methods that are required by the application. The DLL may assume that the class predefinedNamespace.predefinedClass will be available at run time and if it's not throw an exception.
Is this possible? If so, what do I need to read up on?
The idea is that the user enters some data in an application, a method in the DLL is called and based on the 'result' of that method another method is called that is outside the DLL.
I hope this is a little bit clear.
I'm busy with an application and while coding I can see that it can be useful to convert part (one class) of that application at a later stage to a DLL (no experience with creating DLLs, but that is not part of the question).
Below code is part of the class that I consider to move to a DLL
namespace dllNamespace { class classInDLL { predefinedNamespace.predefinedClass myclass = new predefinedNamespace.predefinedClass(); string executeresult=null; public bool doSomework(string strInput) { string result1 = "S2"; string result2 = "b0001"; executeresult = someMethod(result1, result2); } public string getResult() { return executeresult; } private string someMethod(string strA, string strB) { return myclass.execute_Enter(strA, null, strB); } } }
This is the code that will stay in the application or needs to be coded in future applications that use the DLL
namespace predefinedNamespace { class predefinedClass { public string execute_Enter(string strBase, string strInput, string strOutput) { string toExecute = strBase + "_Enter"; System.Reflection.MethodInfo mi = this.GetType().GetMethod(toExecute); if (mi == null) { return genericMethod(toExecute); } else { return (string)mi.Invoke(this, new object[] { strOutput }); } } public string S2_Enter(string strValue) { uint result; if (LibraryWim.Utils.String2UInt(strValue, out result)) { return "Result of entering S2: output value b" + Convert.ToString(result, 2).PadLeft(32, '0'); } else { return "S2: Invalid output defined"; } } public string genericMethod(string strBase) { return String.Format("This is the result of a generic method as no method matching '{0}' is coded by the programmer", strBase); } } }
The idea is that from the DLL user defined methods in a specific class in the application that uses the DLL (that are not known when the DLL is compiled) can be called. So the programmer that uses the DLL will implement the methods that are required by the application. The DLL may assume that the class predefinedNamespace.predefinedClass will be available at run time and if it's not throw an exception.
Is this possible? If so, what do I need to read up on?
The idea is that the user enters some data in an application, a method in the DLL is called and based on the 'result' of that method another method is called that is outside the DLL.
namespace applicationNamespace { private void Go() { dllNamespace.classInDLL theClass = new dllNamespace.classInDLL(); theClass.doSomework("SomeUserInput"); Console.WriteLine(theClass.getResult()); } }
I hope this is a little bit clear.