static Socket() { NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate(); ClassTemplate = owner; owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New)); owner.Set("Invalid", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Invalid)); owner.Set("GetActiveTcpListeners", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetActiveTcpListeners)); owner.Set("GetActiveTcpListeners", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetActiveUdpListeners)); m_SendProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Send); m_BindProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Bind); m_CloseProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Close); m_ConnectProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Connect); m_ReceiveProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Receive); m_AcceptProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Accept); m_ConnectedProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Connected); m_ConnectAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ConnectAsync); m_AcceptAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(AcceptAsync); m_SendAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendAsync); m_ReceiveAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveAsync); m_SendToProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendTo); m_SendToAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendToAsync); m_ReceiveFromProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveFrom); m_ReceiveFromAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveFromAsync); }
static WebSocketClient() { NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate(); ClassTemplate = owner; owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New)); }
protected internal static NSJSValue ToObject(NSJSVirtualMachine machine, object obj) { if (machine == null) { return(null); } if (obj == null) { return(NSJSValue.Null(machine)); } Type owner = obj.GetType(); NSJSObject objective = NSJSObject.New(machine); foreach (MemberInfo mi in InternalCheckKeyMembers(owner).Values) { PropertyInfo pi = mi as PropertyInfo; FieldInfo fi = mi as FieldInfo; object value = null; Type clazz = null; string key = mi.Name; if (pi != null) { clazz = pi.PropertyType; value = pi.GetValue(obj, null); } else { clazz = fi.FieldType; value = fi.GetValue(obj); } NSJSValue result = null; do { if (value == null) { break; } Type element = TypeTool.GetArrayElement(clazz); if (element == null && value is IList) { result = ArrayAuxiliary.ToArray(machine, element, (IList)value); } else if (TypeTool.IsBasicType(clazz) && !TypeTool.IsIPAddress(clazz)) { result = value.As(machine); } else { result = ToObject(machine, value); } } while (false); if (result == null) { result = NSJSValue.Null(machine); } objective.Set(key, result); } NetToObjectCallables callables = InternalCheckNetToObjectCallables(owner); if (callables != null) { if (callables.funcs != null) { foreach (MethodInfo m in callables.funcs) { objective.Set(m.Name, NSJSPinnedCollection.Pinned(Complier(m))); } } if (callables.props != null) { foreach (PropertyInfo p in callables.props) { MethodInfo gm = p.GetGetMethod(); NSJSFunctionCallback get = null; NSJSFunctionCallback set = null; if (gm != null) { get = NSJSPinnedCollection.Pinned(Complier(gm)); } MethodInfo sm = p.GetSetMethod(); if (sm != null) { set = NSJSPinnedCollection.Pinned(Complier(sm)); } if (set != null || get != null) { objective.DefineProperty(p.Name, get, set); } } } objective.Set("Dispose", FDEFAULTDISPOSE); if (!objective.IsDefined("Close")) { objective.Set("Close", FDEFAULTDISPOSE); } NSJSKeyValueCollection.Set(objective, obj); } return(objective); }