public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string str = (string)reader.Value; return(LocationRef.FromLocationID(str ?? "")); }
public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer) { LocationRef ts = (LocationRef)value !; writer.WriteValue(ts.ToString()); }
public object GetValue(DataType dt, int dimension) { if (dimension == 1) { switch (dt) { case DataType.Bool: return(this.GetBool()); case DataType.Byte: return(this.GetByte()); case DataType.SByte: return(this.GetSByte()); case DataType.Int16: return(this.GetShort()); case DataType.UInt16: return(this.GetUShort()); case DataType.Int32: return(this.GetInt()); case DataType.UInt32: return(this.GetUInt()); case DataType.Int64: return(this.GetLong()); case DataType.UInt64: return(this.GetULong()); case DataType.Float32: return(this.GetFloat()); case DataType.Float64: return(this.GetDouble()); case DataType.String: return(this.GetString()); case DataType.ObjectRef: return(ObjectRef.FromEncodedString(this.GetString())); case DataType.LocationRef: return(LocationRef.FromLocationID(this.GetString())); case DataType.URI: return(new Uri(this.GetString())); case DataType.Enum: return(this.GetString()); case DataType.JSON: return(this); case DataType.Guid: return(Guid.Parse(this.GetString())); case DataType.NamedValue: return(this.Object <NamedValue>()); case DataType.LocalDate: return(LocalDate.FromISO8601(this.GetString())); case DataType.LocalTime: return(LocalTime.FromISO8601(this.GetString())); case DataType.LocalDateTime: return(LocalDateTime.FromISO8601(this.GetString())); case DataType.Timestamp: return(Timestamp.FromISO8601(this.GetString())); case DataType.Duration: return(Duration.Parse(this.GetString())); case DataType.Struct: return(json); } } else { switch (dt) { case DataType.Bool: return(this.GetBoolArray()); case DataType.Byte: return(this.GetByteArray()); case DataType.SByte: return(this.GetSByteArray()); case DataType.Int16: return(this.GetShortArray()); case DataType.UInt16: return(this.GetUShortArray()); case DataType.Int32: return(this.GetIntArray()); case DataType.UInt32: return(this.GetUIntArray()); case DataType.Int64: return(this.GetLongArray()); case DataType.UInt64: return(this.GetULongArray()); case DataType.Float32: return(this.GetFloatArray()); case DataType.Float64: return(this.GetDoubleArray()); case DataType.String: return(this.GetStringArray()); case DataType.ObjectRef: return(this.GetStringArray().Select(ObjectRef.FromEncodedString).ToArray()); case DataType.LocationRef: return(this.GetStringArray().Select(LocationRef.FromLocationID).ToArray()); case DataType.URI: return(this.GetStringArray().Select(x => new Uri(x)).ToArray()); case DataType.Enum: return(this.GetStringArray()); case DataType.JSON: return(this); // TODO return DataValue[] case DataType.Guid: return(this.GetStringArray().Select(Guid.Parse).ToArray()); case DataType.NamedValue: return(this.Object <NamedValue[]>()); case DataType.LocalDate: return(this.GetStringArray().Select(LocalDate.FromISO8601).ToArray()); case DataType.LocalTime: return(this.GetStringArray().Select(LocalTime.FromISO8601).ToArray()); case DataType.LocalDateTime: return(this.GetStringArray().Select(LocalDateTime.FromISO8601).ToArray()); case DataType.Timestamp: return(this.GetStringArray().Select(Timestamp.FromISO8601).ToArray()); case DataType.Duration: return(this.GetStringArray().Select(Duration.Parse).ToArray()); case DataType.Struct: return(json); } } return(null); }
public static string ValueToString(LocationRef value) => JsonConvert.ToString(value.LocationID);
public static DataValue FromLocationRef(LocationRef v) => FromJSON(StdJson.ValueToString(v));