Using namespace in LINQPad code (C# Program mode)

edited May 2012
I try to use a namespace in code I have in LINQPad. I want to define a namespaced class I have to use in a call.
Something like:

void Main()
{
Query();
}

namespace MyNamespace
{
public class SyncList
{
public string Id { get; set; }
}
}

So I don't want to reference an assembly. Is this possible?

Regards,
Serge

Comments

  • Hi Serge,

    Why would you want to do that? Could you use an inner class instead?

    void Main()
    {
    Query();
    }

    public static class MyNamespace
    {
    public class SyncList
    {
    public string Id { get; set; }
    }
    }
    Regards,
    Arno
  • I was trying to do the same thing so I could quickly see what all i could get out of GetType a quick and easy namespace.
  • It's important to remember queries are wrapped in an instance of UserQuery. So you're actually writing:
    public class UserQuery
    {
    	void Main()
    	{
    	 	Query();
    	}
    	
    	namespace MyNamespace
    	{
    		 public class SyncList
    		 {
    		 	public string Id { get; set; }
    		 }
    	}
    }
    Which clearly won't work.
  • In case anyone is still interested... You just have to close out the scope (see the } before the "Define other methods..." comment and then reopen the scope (class EOF {).
    void Main()
    {
    	MyNamespace.Test.MyClass.SayHello();
    }
    
    } // Define other methods and classes here
    
    namespace MyNamespace.Test {
    
    class MyClass
    {
    	public static void SayHello()
    	{
    		typeof(MyClass).Dump("My Type");
    		"Hello".Dump();
    	}
    }
    
    }
    
    class EOF {
  • @jwstevensii Yup, "anyone" is still interested (2+ years later). Thanks for the solution, worked like a charm.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!