forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 8
Referencing scripts
filipw edited this page Mar 17, 2013
·
3 revisions
You can reference other scripts from your CSX script by using a #load directive.
Here is an example:
#load "models.csx"
#load "service.csx"
using System;
using ServiceStack.WebHost.Endpoints;
using System.Reflection;
public class AppHost : AppHostHttpListenerBase {
public AppHost() : base("StarterTemplate HttpListener", Assembly.GetExecutingAssembly()) { }
public override void Configure(Funq.Container container) {
Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}");
}
}
var port = "http://*:999/";
var appHost = new AppHost();
appHost.Init();
appHost.Start(port);
Console.WriteLine("listening on {0}", port);
Console.ReadKey();
This allows you to split your script into smaller maintainable bits or simply place common classes into separate CSX file and even reuse between different applications.
-
#loadcan only be placed at the top (before first using statement or code line) of your CSX file. - if you place
#loadinline out script pre-processor will simply exclude it. This is in-line with C# REPL/C# Interactive Window behavior. -
#loadaccepts both relative and absolute paths.
#load is not a scriptcs invention, but rather a C# REPL standard. As a consequence of this, if you have Roslyn CTP installed and you use C# Interactive Window, you can copy paste you CSX file there and the #load directive will be correctly recognized.