Home
Options

Consider add a new language "C# Program with Namespace"?

edited March 2019
Somethings we create a ASP.NET Core MVC demo using LINQPad, but the controller need to be in namespace(instead of in class), this way, code would be a little messy here:

void Main()
{
WebHost
.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseUrls("https://localhost:55555")
.Build()
.Start();
}

class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

public void Configure(IApplicationBuilder app)
{
app.UseMvcWithDefaultRoute();
}
}
}
namespace Controllers
{
public class HomeController : Controller
{
public string Index()
{
return "Hello World";
}
}
}

class EOF {
Is that possible to add a "C# Program with Namespace" way, to make the code much simpler(maybe like this):

namespace App
{
class EntryPoint : UserQuery
{
static void Main()
{
WebHost
.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseUrls("https://localhost:55555")
.Build()
.Start();
}
}

public class HomeController : Controller
{
public string Index()
{
return "Hello World";
}
}

class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

public void Configure(IApplicationBuilder app)
{
app.UseMvcWithDefaultRoute();
}
}
}

Comments

  • Options
    I will look into this, but it's quite a lot of work. And it would make working with data contexts messy and complicated.
  • Options
    JoeAlbahari So do we have any progress of this? Or do you think it's not worthy enough to implement?
  • Options
    This is supported in the latest LINQPad 6 beta (although there's a bug, which will be fixed in the next few days).

    Note that there's no new language option. The 'C# Program' mode now lets you include namespaces as well as types.

    You can also (optionally) keep the main method outside of the namespace declarations, if you need to access a data context:
    void Main()
    {
      // ...
    }
    
    namespace Foo
    {
      //...
    }
Sign In or Register to comment.