edge-reference
v1.0.0
Published
Allows references to be transferred between node.js and .NET applications.
Downloads
8
Maintainers
Readme
edge-reference
A node.js package and associated .NET components that allow JavaScript code to create, access, and maintain references to live .NET objects.
This package contains the functionality required to access .NET using proxies generated by the related edge-generator package.
Installation
$ npm i edge-reference -S
Usage
.NET code is accessed by proxies generated by the edge-generator module. Visit the edge-generator documentation for instructions on generating proxies.
A generated proxy closely resembles its .NET source, and can be imported using its file name:
const Widget = require('./proxies/ExampleCo-Utils-Widget.js');
Constructors
A constructor for a new object is called in the same way as any JavaScript constructor would be:
var instance = new Widget();
At this time, only parameterless constructors are supported.
If for some reason a separate copy of an object is desired, the constructor can be passed a value representing the underlying .NET object associated with an instance:
var secondInstance = new Widget(instance._referenceId);
Properties
Properties are accessed synchronously, and so closely resemble .NET property access:
// Member is a string property in the Widget class
var result = instance.Member;
// StatMember is a static property of the Widget class
var staticResult = Widget.StatMember;
// Setting a property with a public access modifier is also possible:
instance.Member = "newvalue";
// Complex properties can also be read and assigned
var relatedWidget = new Widget();
instance.Sibling = relatedWidget;
Functions
Unlike properties, functions are accesssed asynchronously. This is done by appending a standard node.js-style callback to a function's arguments, as shown below:
var instance = new Widget();
// A function that takes two arguments and returns a string
instance.MemberFunction(arg1, arg2, (err, result) => {
// At this time, the function is complete
if (err) {
console.error('Error');
return;
}
console.log('return value is ' + result);
});
As with properties, non-primitive types can be used, both as arguments and return values:
var instance = new Widget();
var second = new Widget();
// A function that compares two Widget instances and returns one or the other
instance.compareAndReturn(second, (err, result) => {
if (err) {
console.error('Error');
return;
}
console.log('Is instance returned?');
console.log(instance.referenceEquals(result) ? 'yes' : 'no');
});
Built-in Members
Proxies to .NET objects contain a few members by default. These members should not be overridden by .NET code.
View the edge-reference API reference for details.
Disclaimer
The author of this package is in no way affiliated with the edge.js package.
Dedication
Dedicated to Dorothy Gant (1925-2017)
License
Copyright (c) 2017 Steve Westbrook