func = function (language, options) { if (!options) { options = language; language = 'cs'; } if (typeof options === 'string') { if (options.match(/\.dll$/i)) { options = { assemblyFile: options }; } else { options = { source: options }; } } else if (typeof options === 'function') { var originalPrepareStackTrace = Error.prepareStackTrace; var stack; try { Error.prepareStackTrace = function(error, stack) { return stack; }; stack = new Error().stack; } finally { Error.prepareStackTrace = originalPrepareStackTrace; } options = { source: options, jsFileName: stack[1].getFileName(), jsLineNumber: stack[1].getLineNumber() }; } else if (typeof options !== 'object') { throw new Error('Specify the source code as string or provide an options object.'); } if (typeof language !== 'string') { throw new Error('The first argument must be a string identifying the language compiler to use.'); } else if (!options.assemblyFile) { var compilerName = 'edge-' + language.toLowerCase(); var compiler; try { compiler = require(compilerName); } catch (e) { throw new Error("Unsupported language '" + language + "'. To compile script in language '" + language + "' an npm module '" + compilerName + "' must be installed."); } try { options.compiler = compiler.getCompiler(); } catch (e) { throw new Error("The '" + compilerName + "' module required to compile the '" + language + "' language " + "does not contain getCompiler() function."); } if (typeof options.compiler !== 'string') { throw new Error("The '" + compilerName + "' module required to compile the '" + language + "' language " + "did not specify correct compiler package name or assembly."); } if (process.env.EDGE_USE_CORECLR) { options.bootstrapDependencyManifest = compiler.getBootstrapDependencyManifest(); } } if (!options.assemblyFile && !options.source) { throw new Error('Provide DLL or source file name or .NET script literal as a string parmeter, or specify an options object '+ 'with assemblyFile or source string property.'); } else if (options.assemblyFile && options.source) { throw new Error('Provide either an asseblyFile or source property, but not both.'); } if (typeof options.source === 'function') { var match = options.source.toString().match(/[^]*\/\*([^]*)\*\/\s*\}$/); if (match) { options.source = match[1]; } else { throw new Error('If .NET source is provided as JavaScript function, function body must be a /* ... */ comment.'); } } if (options.references !== undefined) { if (!Array.isArray(options.references)) { throw new Error('The references property must be an array of strings.'); } options.references.forEach(function (ref) { if (typeof ref !== 'string') { throw new Error('The references property must be an array of strings.'); } }); } if (options.assemblyFile) { if (!options.typeName) { var matched = options.assemblyFile.match(/([^\\\/]+)\.dll$/i); if (!matched) { throw new Error('Unable to determine the namespace name based on assembly file name. ' + 'Specify typeName parameter as a namespace qualified CLR type name of the application class.'); } options.typeName = matched[1] + '.Startup'; } } else if (!options.typeName) { options.typeName = "Startup"; } if (!options.methodName) { options.methodName = 'Invoke'; } return edge.initi ...
...
You can script C# from a Node.js process:
**ES5**
```javascript
var edge = require('edge');
var helloWorld = edge.func(function () {/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/});
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
...
func = function (language, options) { if (!options) { options = language; language = 'cs'; } if (typeof options === 'string') { if (options.match(/\.dll$/i)) { options = { assemblyFile: options }; } else { options = { source: options }; } } else if (typeof options === 'function') { var originalPrepareStackTrace = Error.prepareStackTrace; var stack; try { Error.prepareStackTrace = function(error, stack) { return stack; }; stack = new Error().stack; } finally { Error.prepareStackTrace = originalPrepareStackTrace; } options = { source: options, jsFileName: stack[1].getFileName(), jsLineNumber: stack[1].getLineNumber() }; } else if (typeof options !== 'object') { throw new Error('Specify the source code as string or provide an options object.'); } if (typeof language !== 'string') { throw new Error('The first argument must be a string identifying the language compiler to use.'); } else if (!options.assemblyFile) { var compilerName = 'edge-' + language.toLowerCase(); var compiler; try { compiler = require(compilerName); } catch (e) { throw new Error("Unsupported language '" + language + "'. To compile script in language '" + language + "' an npm module '" + compilerName + "' must be installed."); } try { options.compiler = compiler.getCompiler(); } catch (e) { throw new Error("The '" + compilerName + "' module required to compile the '" + language + "' language " + "does not contain getCompiler() function."); } if (typeof options.compiler !== 'string') { throw new Error("The '" + compilerName + "' module required to compile the '" + language + "' language " + "did not specify correct compiler package name or assembly."); } if (process.env.EDGE_USE_CORECLR) { options.bootstrapDependencyManifest = compiler.getBootstrapDependencyManifest(); } } if (!options.assemblyFile && !options.source) { throw new Error('Provide DLL or source file name or .NET script literal as a string parmeter, or specify an options object '+ 'with assemblyFile or source string property.'); } else if (options.assemblyFile && options.source) { throw new Error('Provide either an asseblyFile or source property, but not both.'); } if (typeof options.source === 'function') { var match = options.source.toString().match(/[^]*\/\*([^]*)\*\/\s*\}$/); if (match) { options.source = match[1]; } else { throw new Error('If .NET source is provided as JavaScript function, function body must be a /* ... */ comment.'); } } if (options.references !== undefined) { if (!Array.isArray(options.references)) { throw new Error('The references property must be an array of strings.'); } options.references.forEach(function (ref) { if (typeof ref !== 'string') { throw new Error('The references property must be an array of strings.'); } }); } if (options.assemblyFile) { if (!options.typeName) { var matched = options.assemblyFile.match(/([^\\\/]+)\.dll$/i); if (!matched) { throw new Error('Unable to determine the namespace name based on assembly file name. ' + 'Specify typeName parameter as a namespace qualified CLR type name of the application class.'); } options.typeName = matched[1] + '.Startup'; } } else if (!options.typeName) { options.typeName = "Startup"; } if (!options.methodName) { options.methodName = 'Invoke'; } return edge.initi ...
...
You can script C# from a Node.js process:
**ES5**
```javascript
var edge = require('edge');
var helloWorld = edge.func(function () {/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/});
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
...