Frage

Is there a way that I can add a default using directive to ScriptCS? So when I start ScriptCS I do not need to include the namespace for classes in that namespace.

For example, I may need to interact with the Process class within the System.Diagnostics namespace a lot. If I want to create a new instance of this class, I need to do

var proc = new System.Diagnostics.Process();

I would rather do

var proc = new Process();

I know that I can add the using statement each time I start ScriptCS, but I would like it to always be there.

War es hilfreich?

Lösung

You can add additional assembly references and using statements into your en and by writing a Script Pack. You can see an example of injecting using statements in the Web API example.

Andere Tipps

A script pack can do this as Justin mentioned. An alternative option would be to use global modules, example here (https://github.com/scriptcs-contrib/scriptcs-sample-module) however currently they don't support this nicely. If the module had a hook for getting all the services after they were created, you could do this.

I filed this bug (https://github.com/scriptcs/scriptcs/issues/472) to allow addressing this in a much cleaner fashion.

Looks like this can be accomplished by modifying the DefaultNamespaces property of the ScriptExecutor class to include the namespace you want to always have.

You would need to download the source (or fork a new branch in github), modify and compile yourself. You would then put the new ScriptCs.Core assembly in the install folder (C:\Users\USER_NAME\AppData\Roaming\scriptcs). This would replace the existing assembly. If you do this you will lose any changes if you are updating through chocolatey

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top