CodeDom - Namespace/Class interaction between Ns1 and CodeDom's Ns2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thisismykindabyte
    New Member
    • Oct 2008
    • 9

    #1

    CodeDom - Namespace/Class interaction between Ns1 and CodeDom's Ns2

    Hello,

    I was wondering if anyone might know the easiest way to access static methods through a namespace(MyNam espace) from CodeDom generated code?



    Basically I have this in my MyNamespace.For m:

    //////// Most of this below is almost useless jargon just to give an idea of what values are set or not
    public CodeDom.Compile r.CodeDomProvid er provider = new Microsoft.CShar p.CSharpCodePro vider();

    public System.CodeDom. Compiler.Compil erParameters parms = new System.CodeDom. Compiler.Compil erParameters();
    parms.GenerateE xecutable = false;
    parms.GenerateI nMemory = true;
    parms.Reference dAssemblies.Add ("System.dll ");

    public CodeCompileUnit compileUnit = new CodeCompileUnit ();

    public CodeNamespace namespacee = new CodeNamespace(" CodeDomNamespac e");


    namespacee.Impo rts.Add(new CodeNamespaceIm port("System")) ;
    namespacee.Impo rts.Add(new CodeNamespaceIm port("MyNamespa ce"));

    ///End jargon above, my question below:

    Currently in code:

    public string code = @"pubilc static string StringTest()
    {
    return ""the test""
    }
    ";

    but I'd like the code string to say this:

    public string code = @"public static string StringTest()
    {
    return MyNamespace.MyC lass.MyRoutine( "test");
    }


    And in MyRoutine...

    public static string MyRoutine(strin g s)
    {
    s = s + "1";
    return s;
    }


    However when I try this, I keep getting an error in my reflection setup:

    Could not load file or assembly 'file:///C:\Users\rolo\A ppdata\Local\Te mp\przvq1_b.dll ' or one of its dependencies. The system cannot find the file specified.


    I'm pretty new at this, it works fine as long as I don't try modify the string code to use "return MyNamespace.MyC lass.MyRoutine( "test"); " .

    Any ideas on how to do this?
Working...