public static NSJSValue ToArray(NSJSVirtualMachine machine, Type element, IList s) { if (machine == null) { return(null); } int count = s == null ? 0 : s.Count; NSJSArray array = null; if (element == typeof(byte)) { array = NSJSUInt8Array.New(machine, ToArray <byte>(s)); } else if (element == typeof(sbyte)) { array = NSJSInt8Array.New(machine, ToArray <sbyte>(s)); } else if (element == typeof(short)) { array = NSJSInt16Array.New(machine, ToArray <short>(s)); } else if (element == typeof(ushort)) { array = NSJSUInt16Array.New(machine, ToArray <ushort>(s)); } else if (element == typeof(int)) { array = NSJSInt32Array.New(machine, ToArray <int>(s)); } else if (element == typeof(uint)) { array = NSJSUInt32Array.New(machine, ToArray <uint>(s)); } else if (element == typeof(float)) { array = NSJSFloat32Array.New(machine, ToArray <float>(s)); } else if (element == typeof(double)) { array = NSJSFloat64Array.New(machine, ToArray <double>(s)); } else { array = NSJSArray.New(machine, count); for (int i = 0; i < count; i++) { array[i] = ObjectAuxiliary.ToObject(machine, s[i]); } } if (array == null) { return(NSJSValue.Null(machine)); } return(array); }
public static void Copy(IList <int> sourceArray, int sourceIndex, NSJSInt32Array destinationArray, int destinationIndex, int length) { if (sourceArray == null) { throw new ArgumentNullException("sourceArray"); } if (destinationArray == null) { throw new ArgumentNullException("destinationArray"); } for (int i = 0; sourceIndex < length; sourceIndex++, i++) { destinationArray[destinationIndex + i] = sourceArray[sourceIndex]; } }
public static NSJSValue As(this object value, NSJSVirtualMachine machine) { if (machine == null) { return(null); } if (value == null || value == DBNull.Value) { return(NSJSValue.Null(machine)); } if (value is NSJSValue) { return(value as NSJSValue); } Type typeid = value.GetType(); if (typeid == typeof(int) || typeid == typeof(short) || typeid == typeof(sbyte) || typeid == typeof(char)) { return(NSJSInt32.New(machine, Convert.ToInt32(value))); } else if (typeid == typeof(uint) || typeid == typeof(ushort) || typeid == typeof(byte)) { return(NSJSUInt32.New(machine, Convert.ToUInt32(value))); } else if (typeid == typeof(string)) { return(NSJSString.New(machine, value.ToString())); } else if (typeid == typeof(bool)) { return(NSJSBoolean.New(machine, Convert.ToBoolean(value))); } else if (typeid == typeof(DateTime)) { DateTime datetime = Convert.ToDateTime(value); if (NSJSDateTime.Invalid(datetime)) { datetime = NSJSDateTime.Min; } return(NSJSDateTime.New(machine, datetime)); } else if (typeid == typeof(float) || typeid == typeof(double)) { return(NSJSDouble.New(machine, Convert.ToDouble(value))); } else if (typeid == typeof(byte[])) { byte[] buffer = (byte[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSUInt8Array.New(machine, buffer)); } else if (typeid == typeof(sbyte[])) { sbyte[] buffer = (sbyte[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSInt8Array.New(machine, buffer)); } else if (typeid == typeof(short[])) { short[] buffer = (short[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSInt16Array.New(machine, buffer)); } else if (typeid == typeof(ushort[])) { ushort[] buffer = (ushort[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSUInt16Array.New(machine, buffer)); } else if (typeid == typeof(int[])) { int[] buffer = (int[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSInt32Array.New(machine, buffer)); } else if (typeid == typeof(uint[])) { uint[] buffer = (uint[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSUInt32Array.New(machine, buffer)); } else if (typeid == typeof(float[])) { float[] buffer = (float[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSFloat32Array.New(machine, buffer)); } else if (typeid == typeof(double[])) { double[] buffer = (double[])(object)value; if (buffer == null) { return(NSJSValue.Null(machine)); } return(NSJSFloat64Array.New(machine, buffer)); } return(NSJSValue.Null(machine)); }
public static void Copy(IList <int> sourceArray, NSJSInt32Array destinationArray, int length) { ArrayAuxiliary.Copy(sourceArray, 0, destinationArray, 0, length); }
private static HttpClientOptions object2options(NSJSObject options) { if (options == null) { return(null); } HttpClientOptions o = new HttpClientOptions(); NSJSBoolean boolean = options.Get("AllowAutoRedirect") as NSJSBoolean; if (boolean != null) { o.AllowAutoRedirect = boolean.Value; } NSJSInt32 int32 = options.Get("AutomaticDecompression") as NSJSInt32; if (int32 != null) { o.AutomaticDecompression = (DecompressionMethods)int32.Value; } int32 = options.Get("CachePolicy") as NSJSInt32; if (int32 != null) { o.CachePolicy = new HttpRequestCachePolicy((HttpRequestCacheLevel)int32.Value); } int32 = options.Get("MaximumAutomaticRedirections") as NSJSInt32; if (int32 != null) { o.MaximumAutomaticRedirections = int32.Value; } int32 = options.Get("Timeout") as NSJSInt32; if (int32 != null) { o.Timeout = int32.Value; } NSJSString stringt = options.Get("Proxy") as NSJSString; if (stringt != null) { o.Proxy = new WebProxy(stringt.Value); } stringt = options.Get("Referer") as NSJSString; if (stringt != null) { o.Referer = stringt.Value; } NSJSInt32Array int32array = options.Get("Range") as NSJSInt32Array; if (int32array != null) { o.Range = int32array.Buffer; } NSJSArray array = options.Get("Headers") as NSJSArray; if (array != null) { NameValueCollection headers = o.Headers; int count = array.Length; for (int i = 0; i < count; i++) { stringt = array[i] as NSJSString; if (stringt == null) { continue; } headers.Add(headers); } } return(o); }