Package Exports
- clr
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (clr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-clr : Node.js binding for .NET Framework API
Usage:
# npm install clr
# node
> require('clr').init();
> System.Console.WriteLine('Hello, {0}!', 'world');
'Hello, world!'
> var now = new System.DateTime(2013, 7, 1);
> now.ToString();
'2013/07/01 0:00:00'Prerequisites:
- Node.js v0.10.12
- .NET Framework 4.5
- Visual Studio 2012
- Node.js native module build environment
clr.init([options])
Initialize CLR rutime with given options. Returns global namespace.
options{Object}assemblies{Array} - An array of assembly name (partial name, full name or absolute path to .dll/.exe). Defaults to['mscorlib', 'System', 'System.Core'].global{Boolean} - iftrue, CLR global namespace objects are injected into javascript global object. Defaults totrue.
CLR namespaces
- {Object}
CLR namespace objects contain nested namespaces or types.
CLR types
- {Function}
CLR type functions work as constructor for corresponding CLR types. The constructor returns wrapped CLR object.
> var now = new System.DateTime(2013, 7, 1);The code above invokes CLR constructor DateTime (Int32, Int32, Int32)
and returns {Object} that wraps DateTime instance.
CLR type also contains static members.
> var now = System.DateTime.Now;The code above invokes CLR static property getter DateTime.Now.
CLR objects
- {Object}
Javascript object that wraps CLR instance, which contains instance members.
> var now = System.DateTime.Now;
> now.ToString();
'2013/07/01 0:00:00'CLR methods
- {Function}
CLR methods can be invoked as Javascript function. Arguments and return value are marshalled as conventions below.
> System.Console.WriteLine('Hello, {0}!', 'world');
'Hello, world!'CLR properties/fields
- {Getter/Setter}
CLR properties/fields are exposed as object's getter or setter function.
> var now = System.DateTime.Now;CLR events
- {Object}
CLR events can be hooked by add and remove function.
event.add(handler)
Add javascript event handler to specified event.
handler{Function}
event.remove(handler)
Remove javascript event handler from event.
** This isn't working right now **
handler{Function}
Marshaling:
V8 => CLR:
nullorundefined=>nullBoolean=>System.BooleanNubmer=> Any numeric type orSystem.DoubleString=>System.StringFunction=> Any delegate type orSystem.Func<System.Object[], System.Object>Array=> Any type of array orSystem.Object[]object=>System.Dynamic.ExpandoObject
CLR => V8:
null=>nullSystem.Boolean=>Boolean- Any numberic type =>
Number System.String=>String- Any other types => CLR wrapped object
Threading:
You can use .NET threads. All Javascript callback functions are invoked in main event loop.
> var t = new System.Threading.Thread(function () {
> ... console.log('Hello, world!');
> ... });
> t.Start();
'Hello, world!' // will be invoked asynchronously, but in main threadTODO:
- Testing
- Better marshaling
String=> EnumsObject=> DataContract- Handle overflow
- handle cyclic reference
- Better repl support
- Custom inspect function
- New Event api, resembles to EventEmitter
- Prototype chain which reflects CLR inheritance
- Generics
- Array instantiation
- Cast
- Using