public void ShouldProcessList() { //List var list = new Selenium.List(); list.Add(987); var resList = (Selenium.List)driver.ExecuteScript("return arguments;", list); CollectionAssert.AreEquivalent(list, resList); }
public void ShouldProcessList() { //List var list = new Selenium.List(); list.Add(987); var resList = (Selenium.List)driver.ExecuteScript("return arguments;", list); CollectionAssert.AreEquivalent(list, resList); }
private void WriteArray(int depth, JsonArray array) { if (depth-- < 0) { throw new JsonException(E_DepthLimitExceeded, _buffer, _length); } object[] items = array.ToArray(); WriteByte((byte)'['); if (items.Length > 0) { Write(depth, items[0]); for (int i = 1; i < items.Length; i++) { WriteByte((byte)','); Write(depth, items[i]); } } WriteByte((byte)']'); }
private void SerializeArray(JsonArray array, int depth) { if (++depth > DEPTH_MAX) { throw new JsonException("DepthLimitExceeded"); } object[] items = array._items; int count = array.Count; WriteByte((byte)'['); if (count != 0) { SerializeObject(items[0], depth); for (int i = 1; i < count; i++) { WriteByte((byte)','); SerializeObject(items[i], depth); } } WriteByte((byte)']'); }
/// <summary> /// Parses a collection of items. /// </summary> /// <returns>Json object</returns> private static JsonArray ParseArray(byte[] data, ref int index, int depth) { if (depth-- < 0) { throw new JsonException(E_DepthLimitExceeded, data, index); } JsonArray list = new JsonArray(); int c = -1; for (index++; index < data.Length; index++) { c = PeekChar(data, ref index); if (c == ']') { return(list); } object value = ParseNext(data, ref index, depth); list.Add(value); index++; c = PeekChar(data, ref index); if (c != ',') { break; } } if (c == ']') { return(list); } if (index >= data.Length) { throw new JsonException(E_UnexpectedTermination, data, index); } throw new JsonException(E_InvalidArray, data, index); }
private JsonArray DeserializeArray(int depth) { JsonArray list = new JsonArray(); while (MoveNextNonEmptyChar() && _current != ']' && _current != ',') { var obj = DeserializeNext(depth); list.Add(obj); if (!MoveNextNonEmptyChar() || _current != ',') { break; } } if (_current == ']') { return(list); } if (_index >= _length) { throw new JsonException("UnexpectedTermination", _index); } throw new JsonException("InvalideArray", _index); }
private void Write(int depth, object obj) { if (obj == null) { WriteLiteral("null"); return; } Type objType = obj.GetType(); switch (Type.GetTypeCode(objType)) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: WriteNumber((IConvertible)obj); return; case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Single: WriteNumber((IFormattable)obj); return; case TypeCode.String: WriteQuotedString((string)obj); return; case TypeCode.Char: WriteQuotedString((char)obj); return; case TypeCode.Boolean: WriteBool((bool)obj); return; case TypeCode.DBNull: WriteLiteral("null"); return; case TypeCode.DateTime: WriteDateTime((System.DateTime)obj); return; } if (objType.IsArray) { Type eleType = objType.GetElementType(); switch (Type.GetTypeCode(eleType)) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: WriteArray(depth, (IConvertible[])obj, WriteNumber); return; case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Single: WriteArray(depth, (IFormattable[])obj, WriteNumber); return; case TypeCode.String: WriteArray(depth, (string[])obj, WriteQuotedString); return; case TypeCode.Char: WriteArray(depth, (char[])obj, WriteQuotedString); return; case TypeCode.Boolean: WriteArray(depth, (bool[])obj, WriteBool); return; case TypeCode.DBNull: WriteLiteral("null"); return; case TypeCode.DateTime: WriteArray(depth, (DateTime[])obj, WriteDateTime); return; } IConvertible[] arrConv = obj as IConvertible[]; if (arrConv != null) { WriteArray(depth, arrConv, WriteNumber); return; } } JsonObject objDict = obj as JsonObject; if (objDict != null) { WriteDictionary(depth, objDict); return; } JsonArray objList = obj as JsonArray; if (objList != null) { WriteArray(depth, objList); return; } IJsonObject objObj = obj as IJsonObject; if (objObj != null) { var ocdict = objObj.SerializeJson(); WriteDictionary(depth, ocdict); return; } IEnumerable objEnum = obj as IEnumerable; if (objEnum != null && objType.IsSerializable) { WriteEnumerable(depth, objEnum); return; } IJsonBinary objBinary = obj as IJsonBinary; if (objBinary != null) { WriteBinary(objBinary); return; } Bitmap objBitmap = obj as Bitmap; if (objBitmap != null) { WriteImage(objBitmap); return; } throw new JsonException(string.Format("Object of type {0} is not serializable.", objType.Name)); }
private JsonArray DeserializeArray(int depth) { JsonArray list = new JsonArray(); while (MoveNextNonEmptyChar() && _current != ']' && _current != ',') { var obj = DeserializeNext(depth); list.Add(obj); if (!MoveNextNonEmptyChar() || _current != ',') break; } if (_current == ']') return list; if (_index >= _length) throw new JsonException("UnexpectedTermination", _index); throw new JsonException("InvalideArray", _index); }
private void SerializeObject(object obj, int depth) { if (obj == null) { WriteBytes("null"); return; } Type t = obj.GetType(); switch (Type.GetTypeCode(t)) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: SerializeConvertible((IConvertible)obj); return; case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Single: SerializeFloat((IFormattable)obj); return; case TypeCode.String: SerializeString((string)obj); return; case TypeCode.Char: SerializeCharacter((char)obj); return; case TypeCode.Boolean: SerializeBool((bool)obj); return; case TypeCode.DBNull: WriteBytes("null"); return; case TypeCode.DateTime: SerializeDateTime((System.DateTime)obj); return; } if (t.IsArray) { Type te = t.GetElementType(); switch (Type.GetTypeCode(te)) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: SerializeArray((IConvertible[])obj, SerializeConvertible); return; case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Single: SerializeArray((IFormattable[])obj, SerializeFloat); return; case TypeCode.String: SerializeArray((string[])obj, SerializeString); return; case TypeCode.Char: SerializeArray((char[])obj, SerializeCharacter); return; case TypeCode.Boolean: SerializeArray((bool[])obj, SerializeBool); return; case TypeCode.DBNull: WriteBytes("null"); return; case TypeCode.DateTime: SerializeArray((DateTime[])obj, SerializeDateTime); return; } IConvertible[] arrConv = obj as IConvertible[]; if (arrConv != null) { SerializeArray(arrConv, SerializeConvertible); return; } } JsonObject objDict = obj as JsonObject; if (objDict != null) { SerializeDictionary(objDict, depth); return; } JsonArray objList = obj as JsonArray; if (objList != null) { SerializeArray(objList, depth); return; } IJsonObject objObj = obj as IJsonObject; if (objObj != null) { var ocdict = objObj.SerializeJson(); SerializeDictionary(ocdict, depth); return; } IEnumerable objEnum = obj as IEnumerable; if (objEnum != null && t.IsSerializable) { SerializeEnumerable(objEnum, depth); return; } IJsonBinary objBinary = obj as IJsonBinary; if (objBinary != null) { SerializeBinary(objBinary); return; } throw new JsonException(string.Format( "Object of type {0} is not serializable\n{1}{0}" , t.Name, this.DebugValue)); }