Using namespace in LINQPad code (C# Program mode)
Options
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
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?
Regards,
void Main()
{
Query();
}
public static class MyNamespace
{
public class SyncList
{
public string Id { get; set; }
}
}
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.
-
Still useful in 2018!
-
Thanks for the solution. That helped me.
And, FYI, we don't need the
}
class EOF {
Just keep the namespace open (i.e. without the closing brace } and it works great. -
Still helpful in 2023, my man jwstevensii is a legend!
-
I presume you're using LINQPad 5? This hack is not necessary in LINQPad 7.