public static NSJSValue ToObject(NSJSVirtualMachine machine, IPHostEntry host) { if (machine == null) { return(null); } if (host == null) { return(NSJSValue.Null(machine)); } NSJSObject entry = NSJSObject.New(machine); entry.Set("HostName", host.HostName); entry.Set("AddressList", ArrayAuxiliary.ToArray(machine, host.AddressList)); string[] aliases = host.Aliases; NSJSArray array = NSJSArray.New(machine, aliases.Length); for (int i = 0; i < aliases.Length; i++) { array[i] = NSJSString.New(machine, aliases[i]); } entry.Set("Aliases", array); return(entry); }
public static MailMessage ToMailMessage(NSJSValue value) { NSJSObject mail = value as NSJSObject; if (mail == null) { return(null); } MailMessage message = new MailMessage(); message.Body = ValueAuxiliary.ToString(mail.Get("Body")); message.Subject = ValueAuxiliary.ToString(mail.Get("Subject")); message.IsBodyHtml = ValueAuxiliary.ToBoolean(mail.Get("IsBodyHtml")); message.BodyEncoding = Encoding.UTF8; message.HeadersEncoding = Encoding.UTF8; message.SubjectEncoding = Encoding.UTF8; MailAddress address = ToMailAddress(mail.Get("From")); if (address == null) { return(null); } message.From = address; message.Sender = ToMailAddress(mail.Get("Sender")); ArrayAuxiliary.Fill(mail.Get("To"), message.To); ArrayAuxiliary.Fill(mail.Get("ReplyToList"), message.ReplyToList); ArrayAuxiliary.Fill(mail.Get("Attachments"), message.Attachments); return(message); }
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); }
public static void Copy(IList <double> sourceArray, NSJSFloat64Array destinationArray, int length) { ArrayAuxiliary.Copy(sourceArray, 0, destinationArray, 0, length); }
public static void Copy(IList <uint> sourceArray, NSJSUInt32Array destinationArray, int length) { ArrayAuxiliary.Copy(sourceArray, 0, destinationArray, 0, length); }
public static void Copy(IList <sbyte> sourceArray, NSJSInt8Array destinationArray, int length) { ArrayAuxiliary.Copy(sourceArray, 0, destinationArray, 0, length); }