views:

69

answers:

2
+1  Q: 

Design problem.

Hi,

I have a sample application and user control which uses separate copy of structure and enum. I want to know how to define this enum and structure, in order to use in my sample application as well as in my user control without having multiple definitions . i.e. only one copy of enum and structure should be present. Please let me know how to do it.. If I do this code duplication can be avoided.. Thanks

+4  A: 

Define the types you want to use in more than one place in a DLL. Just add a new project of type "Class Library" to your soultion, put your code in it and add references to this project in all the other projects.

Maximilian Mayerl
Thanks for the reply,if i have 10 different enums then i need to make 10 different DLL's.its increases the complexity i.e count of DLL are more.But in c/c++ only one ".h" is enough to access across the project. so how to achieve this in c#.Thanks
Shadow
Why would you need 10 different DLLs? You are creating a shared class library. You would just define all your enums in the library and reference the library in all your projects that use them.
James
yeah,, i do create as u told.. but the problem is code separation will not be there i mean if i give that .dll to some body they will be having access to all the unused enums. but in c++ number of .h increases here number of .dll increases
Shadow
I still can't see where the multiple dlls are going to come about. If you have 10 enums that need to be used across multiple projects. If you put them into a separate library project, then reference that library project in the projects that require them, then I can't see the need for defining multiple dlls?
James
And what is the problem with somebody having access to "unused" enums?
Maximilian Mayerl
@James: yes i do create a DLL, which has 10 enums.then i will reference them into multiple project i agree with this solution. But all projects which refer a DLL may not require all enum's, in this case your solution comes i.e creating multiple DLL and distribute which ever necessary to project. Is any other way to achieve this? i mean with out making DLL,like making .h file in C/C++ using it,is there any way similar to C/C++ in C#.
Shadow
No, there is no other way. Just put ALL your enums in ONE DLL and add this to the project. Unused enums will not be a problem.
Maximilian Mayerl
+1  A: 

I would create a separate library project for this. Place all your common code into that and reference it in both your application/user control projects. Alternatively, create your UserControl under the same project as your application.

James