tags:

views:

56

answers:

3

Hi, I would like to know how can I embedd a code source file (if possible), something like that:

class X
{
include "ClassXsource"
}

My second question - Can I build DLL or something like that for my colleagues to use? I need them to be able to call methods from my "part" but do not modify or view their content. Basically just use namespace "MyNamespace" and call its methods, but I have never done anything like that. Thanks

+3  A: 

The C# compiler does not support include files. You can of course use a pre-compiler, that would read your source code files, and insert the included files into them, before passing the new files to the compiler.

As for producing a class library, sure. You can do it in two ways:

  1. You can make the project source code available, so that they would add the project with all its files into their own project, and thus compile your class library as part of their solution.
  2. You can compile it yourself, which produces an assembly file on disk (YourClassLibrary.dll), and then give that file to your co-workers. They would then add a reference to the file and can start using it.
Lasse V. Karlsen
+1  A: 

You can't, except by using some external preprocessor. You could use T4, which is already used by Microsoft as a text templating tool, e.g. for code generation with the Entity Framework; see this MSDN documentation page.

With T4, you would include another source file like this:

<#@ include file="c:\test.txt" #>

Now to the more fundamental point: Including source files is not how you usually create libraries, especially not in .NET. What you would do is create a class (probably a static class) containing your methods. You would then compile this and give the resulting assembly (.dll file) to your colleagues. They will be able to load it as a reference into their .NET project and use your class.

public static class MyFunctions
{
    public static void MyMethod1(...) { ... }
    public static int  MyMethod2(...) { ... }
    ...
}

(Of course such code is more procedural than good object-oriented design, but this may or may not be an issue for you.)

stakx
A: 

No, not in that way. But you can create a class library and put all classes they need to use there. They simply add a reference to that dll from their project and import the namespace, voila, they can use the classes.

Femaref