示例#1
0
        public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            string?str = (string?)reader.Value;

            if (str == null)
            {
                return(null);
            }
            return(Duration.Parse(str));
        }
示例#2
0
        public void ReadXml(XmlReader reader)
        {
            string m = reader["mode"];

            switch (m)
            {
            case "None":
                Mode = HistoryMode.None;
                break;

            case "Complete":
                Mode = HistoryMode.Complete;
                break;

            case "ValueOrQualityChanged":
                Mode = HistoryMode.ValueOrQualityChanged;
                break;

            case "Interval":
                Mode = HistoryMode.Interval;
                break;

            case "IntervalExact":
                Mode = HistoryMode.IntervalExact;
                break;

            case "IntervalOrChanged":
                Mode = HistoryMode.IntervalOrChanged;
                break;

            case "IntervalExactOrChanged":
                Mode = HistoryMode.IntervalExactOrChanged;
                break;

            default:
                throw new Exception("Unknown HistoryMode: " + m);
            }
            string intv = reader["interval"];

            if (intv != null)
            {
                Interval = Duration.Parse(intv);
            }
            string off = reader["offset"];

            if (off != null)
            {
                Offset = Duration.Parse(off);
            }
            reader.Read();
        }
示例#3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            string str = (string)reader.Value;

            return(Duration.Parse(str));
        }
示例#4
0
        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);
        }