开发者

Dynamically import C# classes from other directories

I have a Visual Studio C# project and a bunch of .cs (C# classes) in different directories inside one subdirectory called "OtherClasses". The directory structure will be:

<Visual C# Directory>
      <bin>
      <obj>
      <Properties>
      <OtherClasses>
           <Package1>
           <Package2>

So in each Package directory there are C# classes. My question is: Is there any way to inkove those classes开发者_如何转开发 from the main class inside the Visual C# directory?

Also I would like that if the user select Package N in the program then only the classes of that specific package are invoked. I don't know if it is possible to acheive this in some way.

Thanks.


Yes, you can create assemblies for each of the packages, and then load them dynamically based on what the user selects. You can even create these assemblies dynamically at run time by compiling the source files using the built in c# compiler.


Visual Studio couldn't care less about the directory structure. Either the (.cs) files are included in the project and are compiled, or they aren't included in the project and thus aren't compiled. So regardless of what folder the different files are in, they will be able to invoke each other as long as their visibility (internal or public) permits it.

If you want to the user to be able to choose from different sets of classes, you'll have to use some other method to make the distinction besides relying on the directory of the source code.

Edit
This assuming you are compiling your .cs files as one project. If you are going to compile folders of code when the program runs, then how the code interacts will be determined by the specifics of the method you use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜