public static int Fill(NSJSValue source, NameValueCollection destination) { NSJSObject objecttive = source as NSJSObject; int count = 0; if (objecttive == null || destination == null) { return(count); } foreach (string key in objecttive.GetAllKeys()) { if (string.IsNullOrEmpty(key)) { continue; } destination.Set(key, ValueAuxiliary.ToString(objecttive.Get(key))); count++; } return(count); }
public static int Fill(NSJSValue source, NSJSValue destination) { NSJSObject sourceObject = source as NSJSObject; NSJSObject destinationObject = destination as NSJSObject; int count = 0; if (sourceObject == null || destinationObject == null) { return(count); } foreach (string key in sourceObject.GetAllKeys()) { if (string.IsNullOrEmpty(key)) { continue; } count++; NSJSValue value = sourceObject.Get(key); destinationObject.Set(key, value); } return(count); }
private static object ToObject(ConstructorInfo constructor, NSJSObject obj) { if (constructor == null || obj == null) { return(null); } object o = constructor.Invoke(null); IDictionary <string, MemberInfo> members = InternalCheckKeyMembers(constructor.DeclaringType); foreach (string key in obj.GetAllKeys()) { MemberInfo mi; if (!members.TryGetValue(key, out mi)) { continue; } PropertyInfo pi = mi as PropertyInfo; FieldInfo fi = mi as FieldInfo; Type mt = pi != null ? pi.PropertyType : fi.FieldType; Func <NSJSValue, object> converter = (Func <NSJSValue, object>)InternalCheckConverter(mt, 1); if (converter == null) { throw new InvalidOperationException(string.Format("Unable to find a valid JavaScript value To {0} type converter", mt.FullName)); } object value = converter(obj.Get(mi.Name)); if (pi == null) { fi.SetValue(o, value); } else { pi.SetValue(o, value, null); } } return(o); }