public static PathValue CreateArray(PathValueType valueType, int length) { if (valueType == PathValueType.Array) throw new ArgumentException("Arrays of arrays are not supported."); if (valueType == PathValueType.Null) throw new ArgumentException("Nulls are not valid arrays element types."); Type elementType; if (valueType == PathValueType.Boolean) elementType = typeof(bool); else if (valueType == PathValueType.Byte) elementType = typeof(byte); else if (valueType == PathValueType.Int16) elementType = typeof(short); else if (valueType == PathValueType.Int32) elementType = typeof(int); else if (valueType == PathValueType.Int64) elementType = typeof(long); else if (valueType == PathValueType.Single) elementType = typeof(float); else if (valueType == PathValueType.Double) elementType = typeof(double); else if (valueType == PathValueType.DateTime) elementType = typeof(DateTime); else if (valueType == PathValueType.String) elementType = typeof(string); else elementType = typeof (object); return new PathValue(Array.CreateInstance(elementType, length)); }
public static PathValue CreateArray(PathValueType valueType, int length) { if (valueType == PathValueType.Array) { throw new ArgumentException("Arrays of arrays are not supported."); } if (valueType == PathValueType.Null) { throw new ArgumentException("Nulls are not valid arrays element types."); } Type elementType; if (valueType == PathValueType.Boolean) { elementType = typeof(bool); } else if (valueType == PathValueType.Byte) { elementType = typeof(byte); } else if (valueType == PathValueType.Int16) { elementType = typeof(short); } else if (valueType == PathValueType.Int32) { elementType = typeof(int); } else if (valueType == PathValueType.Int64) { elementType = typeof(long); } else if (valueType == PathValueType.Single) { elementType = typeof(float); } else if (valueType == PathValueType.Double) { elementType = typeof(double); } else if (valueType == PathValueType.DateTime) { elementType = typeof(DateTime); } else if (valueType == PathValueType.String) { elementType = typeof(string); } else { elementType = typeof(object); } return(new PathValue(Array.CreateInstance(elementType, length))); }
internal PathValue(object value) { valueTypeCode = GetTypeCode(value, out valueType); if (valueTypeCode == PathValueType.Array) { array = (Array) value; } else if (valueTypeCode == PathValueType.Struct) { value = PathStruct.FromObject(value); } this.value = value; }
private PathValueType ReadType(PathValueType expected) { PathValueType type = (PathValueType)input.ReadByte(); if (type != expected) { throw new InvalidOperationException("The type '" + type + "' read does not match the type '" + expected + "' that was expected."); } return(type); }
internal PathValue(object value) { valueTypeCode = GetTypeCode(value, out valueType); if (valueTypeCode == PathValueType.Array) { array = (Array)value; } else if (valueTypeCode == PathValueType.Struct) { value = PathStruct.FromObject(value); } this.value = value; }
private PathValue ReadValue(PathValueType type) { if (type == PathValueType.Null) return PathValue.Null; if (type == PathValueType.Boolean) return new PathValue(input.ReadBoolean()); if (type == PathValueType.Byte) return new PathValue(input.ReadByte()); if (type == PathValueType.Int16) return new PathValue(input.ReadInt16()); if (type == PathValueType.Int32) return new PathValue(input.ReadInt32()); if (type == PathValueType.Int64) return new PathValue(input.ReadInt64()); if (type == PathValueType.Single) return new PathValue(input.ReadSingle()); if (type == PathValueType.Double) return new PathValue(input.ReadDouble()); if (type == PathValueType.String) { int length = input.ReadInt32(); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.Append(input.ReadChar()); } return new PathValue(sb.ToString()); } if (type == PathValueType.DateTime) return new PathValue(UnixDateTime.ToDateTime(input.ReadInt64())); if (type == PathValueType.Struct) { int memberCount = input.ReadInt32(); PathStruct pathStruct = new PathStruct(); for (int i = 0; i < memberCount; i++) { string memberName = ReadValue(PathValueType.String); PathValue value = ReadValue(); pathStruct.SetValue(memberName, value); } return new PathValue(pathStruct); } if (type == PathValueType.Array) { PathValueType elementType = (PathValueType) input.ReadByte(); int length = input.ReadInt32(); PathValue array = PathValue.CreateArray(elementType, length); for (int i = 0; i < length; i++) { PathValue value = ReadValue(elementType); array.SetValue(i, value.Value); } return array; } throw new NotSupportedException(); }
private PathValueType ReadType(PathValueType expected) { PathValueType type = (PathValueType) input.ReadByte(); if (type != expected) throw new InvalidOperationException("The type '" + type + "' read does not match the type '" + expected + "' that was expected."); return type; }
private PathValue ReadValue(PathValueType type) { if (type == PathValueType.Null) { return(PathValue.Null); } if (type == PathValueType.Boolean) { return(new PathValue(input.ReadBoolean())); } if (type == PathValueType.Byte) { return(new PathValue(input.ReadByte())); } if (type == PathValueType.Int16) { return(new PathValue(input.ReadInt16())); } if (type == PathValueType.Int32) { return(new PathValue(input.ReadInt32())); } if (type == PathValueType.Int64) { return(new PathValue(input.ReadInt64())); } if (type == PathValueType.Single) { return(new PathValue(input.ReadSingle())); } if (type == PathValueType.Double) { return(new PathValue(input.ReadDouble())); } if (type == PathValueType.String) { int length = input.ReadInt32(); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.Append(input.ReadChar()); } return(new PathValue(sb.ToString())); } if (type == PathValueType.DateTime) { return(new PathValue(UnixDateTime.ToDateTime(input.ReadInt64()))); } if (type == PathValueType.Struct) { int memberCount = input.ReadInt32(); PathStruct pathStruct = new PathStruct(); for (int i = 0; i < memberCount; i++) { string memberName = ReadValue(PathValueType.String); PathValue value = ReadValue(); pathStruct.SetValue(memberName, value); } return(new PathValue(pathStruct)); } if (type == PathValueType.Array) { PathValueType elementType = (PathValueType)input.ReadByte(); int length = input.ReadInt32(); PathValue array = PathValue.CreateArray(elementType, length); for (int i = 0; i < length; i++) { PathValue value = ReadValue(elementType); array.SetValue(i, value.Value); } return(array); } throw new NotSupportedException(); }
public PathValue ReadValue() { PathValueType type = (PathValueType)input.ReadByte(); return(ReadValue(type)); }