private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { string script; if (reference == 0) { script = string.Format("delete {0}", this.ns); } else { var origin = this.origin; if (origin != null) script = string.Format("{0}.$releaseObject(${1})", origin.ns, reference); else return; } var _ = _context.NKevaluateJavaScript(script); _context = null; _origin = null; _context = null; _origin = null; reference = 0; ns = null; disposedValue = true; } }
internal NKScriptValue(string ns, NKScriptContext context, NKScriptValue origin) { this.ns = ns; _context = context; if (origin != null) _origin = origin; else _origin = this; }
internal static void setNKScriptValue(this object obj, NKScriptValue value) { if (value != null) { dictionary[obj] = value; } else { dictionary.Remove(obj); } }
// Create new instance of plugin for given channel internal NKScriptValueNative(string ns, NKScriptChannelProtocol channel, int instanceid, object[] args, bool create) : base(ns, channel.context, null) { if (create != true) { throw new ArgumentException(); } this._channel = channel; this._instanceid = instanceid; Type cls = channel.typeInfo.pluginType; var constructor = channel.typeInfo.DefaultConstructor(); if (constructor == null || !constructor.isConstructor()) { throw new ArgumentException(String.Format("!Plugin class {0} is not a constructor"), cls.Name); } object[] argsWrapped = args.Select(wrapScriptObject).ToArray <object>(); NKScriptValue promise = null; var arity = constructor.arity; if (arity == argsWrapped.Length - 1 || arity < 0) { promise = argsWrapped.Last() as NKScriptValue; argsWrapped.Take(argsWrapped.Length - 1).ToArray(); } // if (constructor.name == "initByScriptWithArguments:") // { // arguments = [arguments] // } // TO DO map nulls to nulls if needed object instance = NKScriptInvocation.construct(cls, (ConstructorInfo)constructor.method, argsWrapped); if (instance == null) { throw new ArgumentException(String.Format("!Failed to create instance for plugin class {0}"), cls.Name); } proxy = bindObject(instance); syncProperties(); if (promise != null) { promise.invokeMethod("resolve", new[] { this }); } }
internal NKScriptValue(int reference, NKScriptContext context, NKScriptValue origin) { this.ns = String.Format("{0}.$references[{1}]", origin.ns, reference); this.reference = reference; _context = context; }