Common Variables in Main, Dlls, and Functions in .cs
-
I have many functions that employ some global variables that are common to all such functions, such as the language variable, to display error messages in the proper language. I want to make various compiled dlls which in turn employs those functions. If those variables are in a global structure, when I create a main that uses the dll, in the main i have to define that structure or include the same .cs and, in that way, there are two different copies of that structure with the same name. That produces the error CS0433. I can define a structure in the dll and in the Main I can use it, making a copy of the Main variables to the dll structure. But then if on the Main changes one of the variables, The dll does not have the updated value, I have to do it with every dll I use. Now you think the problem is bigger if there is more than one dll. That is impractical. I continue with the problem not solved and raised in: Https://www.codeproject.com/Forums/1649/Csharp.aspx?fid=1649&df=90&mpp=25&sort=Position&spc=Relaxed&view=Normal&fr=51#xx0xx Can anyone make a practical example? Thank you.
-
I have many functions that employ some global variables that are common to all such functions, such as the language variable, to display error messages in the proper language. I want to make various compiled dlls which in turn employs those functions. If those variables are in a global structure, when I create a main that uses the dll, in the main i have to define that structure or include the same .cs and, in that way, there are two different copies of that structure with the same name. That produces the error CS0433. I can define a structure in the dll and in the Main I can use it, making a copy of the Main variables to the dll structure. But then if on the Main changes one of the variables, The dll does not have the updated value, I have to do it with every dll I use. Now you think the problem is bigger if there is more than one dll. That is impractical. I continue with the problem not solved and raised in: Https://www.codeproject.com/Forums/1649/Csharp.aspx?fid=1649&df=90&mpp=25&sort=Position&spc=Relaxed&view=Normal&fr=51#xx0xx Can anyone make a practical example? Thank you.
Regequion wrote:
Can anyone make a practical example
Most unlikely since what you are trying to do does not make sense. As I told you before in your original question, you need to rethink your design. If a DLL requires special parameters supplied by the main program then you need to add a method to the DLL to receive those parameters and use them to produce whatever customised results are required. There is no reason why you should ever require two versions of the same source module or structure to make this work.
-
Regequion wrote:
Can anyone make a practical example
Most unlikely since what you are trying to do does not make sense. As I told you before in your original question, you need to rethink your design. If a DLL requires special parameters supplied by the main program then you need to add a method to the DLL to receive those parameters and use them to produce whatever customised results are required. There is no reason why you should ever require two versions of the same source module or structure to make this work.
I'm already rethinking my design, what I do not know is how to do it. This matter is not well finished technically. Focusing and exposing this topic is difficult. 1.- I have some functions in .cs files that I use in both Main and functions .cs and DLLs. These functions use a structure with some variables of general use. In order to compile those functions for the Main or if I want to create a dll, the structure must exist for functions such as in a .cs file. Imagine that in the cs the structure is called Name_Common.Cls_Common.StCommon 2.- When using Main, I need to add the definition of that structure of the same .cs That already produces the mentioned error of ambiguity. But if I want with an alias to refer to the structure of the dlls, I have to enter the variables every time from Main in each structure of each dll, being in Main with alias: using Name_Common_Main = Dll.Name_Common for the first dll. But, and for the second dll? I can not add another using or if? And those variables, when they are not global, when they change their value will not be updated. I'm stuck, mentally and by software. How do people do?
-
I'm already rethinking my design, what I do not know is how to do it. This matter is not well finished technically. Focusing and exposing this topic is difficult. 1.- I have some functions in .cs files that I use in both Main and functions .cs and DLLs. These functions use a structure with some variables of general use. In order to compile those functions for the Main or if I want to create a dll, the structure must exist for functions such as in a .cs file. Imagine that in the cs the structure is called Name_Common.Cls_Common.StCommon 2.- When using Main, I need to add the definition of that structure of the same .cs That already produces the mentioned error of ambiguity. But if I want with an alias to refer to the structure of the dlls, I have to enter the variables every time from Main in each structure of each dll, being in Main with alias: using Name_Common_Main = Dll.Name_Common for the first dll. But, and for the second dll? I can not add another using or if? And those variables, when they are not global, when they change their value will not be updated. I'm stuck, mentally and by software. How do people do?
One of the first questions you need to ask is whether you actually need a DLL in the first place. Will this DLL be used by other applications, or is it specific only to this one? If the latter, then you probably do not need to separate out the methods it provides. As to the rest, I still cannot quite grasp what it is that you are trying to achieve. Using a structure to pass data between classes or methods does not need to be over complicated. It is just a matter of providing all the right information in the right place at the right time. As to variables changing during the lifecycle of an application, this can easily be captured by the use of events and delegates.
-
One of the first questions you need to ask is whether you actually need a DLL in the first place. Will this DLL be used by other applications, or is it specific only to this one? If the latter, then you probably do not need to separate out the methods it provides. As to the rest, I still cannot quite grasp what it is that you are trying to achieve. Using a structure to pass data between classes or methods does not need to be over complicated. It is just a matter of providing all the right information in the right place at the right time. As to variables changing during the lifecycle of an application, this can easily be captured by the use of events and delegates.