Exemple #1
0
        public DxArrayValue ForcePathArray(string path)
        {
            string[] pathNames = path.Split('.');
            if (pathNames.Length == 0)
            {
                return(null);
            }
            DxBaseValue vbase = this[pathNames[0]];

            if (vbase == null || vbase.Type != ValueType.VT_Map)
            {
                vbase = NewRecord(pathNames[0]);
            }
            for (int i = 1; i < pathNames.Length - 1; i++)
            {
                DxRecordValue oldbase = (DxRecordValue)vbase;
                if (vbase.Type == ValueType.VT_Map)
                {
                    vbase = ((DxRecordValue)vbase)[pathNames[i]];
                    if (vbase == null || vbase.Type != ValueType.VT_Map)
                    {
                        vbase = oldbase.NewRecord(pathNames[i]);
                    }
                }
                else
                {
                    vbase = vbase.Parent;
                    vbase = ((DxRecordValue)vbase).NewRecord(pathNames[i - 1]).NewRecord(pathNames[i]);
                }
            }
            return(((DxRecordValue)vbase).NewArray(pathNames[pathNames.Length - 1]));
        }
Exemple #2
0
        public DxBaseValue ValueByPath(string path)
        {
            string[] pathNames = path.Split('.');
            if (pathNames.Length == 0)
            {
                return(null);
            }
            DxBaseValue vbase = this[pathNames[0]];

            if (vbase == null || vbase.Type != ValueType.VT_Map)
            {
                return(null);
            }
            for (int i = 1; i < pathNames.Length - 1; i++)
            {
                if (vbase.Type == ValueType.VT_Map)
                {
                    vbase = ((DxRecordValue)vbase)[pathNames[i]];
                    if (vbase == null || vbase.Type != ValueType.VT_Map)
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(((DxRecordValue)vbase)[pathNames[pathNames.Length - 1]]);
        }
Exemple #3
0
        public DxRecordValue NewRecord(string keyName)
        {
            if (keyName == "")
            {
                return(null);
            }
            DxBaseValue value  = null;
            bool        haskey = records.TryGetValue(keyName, out value);

            if (haskey)
            {
                if (value.Type == ValueType.VT_Map)
                {
                    ((DxRecordValue)value).Clear();
                    return((DxRecordValue)value);
                }
                else if (value.Type == ValueType.VT_Array)
                {
                    ((DxArrayValue)value).Clear();
                }
            }
            DxRecordValue result = new DxRecordValue();

            result.parent = this;
            if (haskey)
            {
                records[keyName] = result;
            }
            else
            {
                records.Add(keyName, result);
            }
            return(result);
        }
        public DxArrayValue GetArray(int idx)
        {
            DxBaseValue result = this[idx];

            if (result != null && result.Type == ValueType.VT_Array)
            {
                return((DxArrayValue)result);
            }
            return(null);
        }
Exemple #5
0
        public DxRecordValue GetRecord(string keyName)
        {
            DxBaseValue result = this[keyName];

            if (result != null && result.Type == ValueType.VT_Map)
            {
                return((DxRecordValue)result);
            }
            return(null);
        }
Exemple #6
0
        public int IntByPath(string path, int DefaultValue = 0)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsInt);
            }
            return(DefaultValue);
        }
Exemple #7
0
        public bool BoolByPath(string path, bool DefaultValue = false)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsBoolean);
            }
            return(DefaultValue);
        }
Exemple #8
0
        public float FloatByPath(string path, float DefaultValue = 0)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsFloat);
            }
            return(DefaultValue);
        }
Exemple #9
0
        public double DoubleByPath(string path, double DefaultValue = 0)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsDouble);
            }
            return(DefaultValue);
        }
Exemple #10
0
        public DxRecordValue RecordByPath(string path)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null && v.Type == ValueType.VT_Map)
            {
                return((DxRecordValue)v);
            }
            return(null);
        }
Exemple #11
0
        public string StringByPath(string path, string DefaultValue = "")
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsString);
            }
            return(DefaultValue);
        }
Exemple #12
0
        public DxArrayValue ArrayByPath(string path)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null && v.Type == ValueType.VT_Array)
            {
                return((DxArrayValue)v);
            }
            return(null);
        }
        public DxRecordValue GetRecord(int idx)
        {
            DxBaseValue result = this[idx];

            if (result != null && result.Type == ValueType.VT_Map)
            {
                return((DxRecordValue)result);
            }
            return(null);
        }
Exemple #14
0
        public long Int64ByPath(string path, long DefaultValue = 0)
        {
            DxBaseValue v = ValueByPath(path);

            if (v != null)
            {
                return(v.AsInt64);
            }
            return(DefaultValue);
        }
Exemple #15
0
        public DxArrayValue GetArray(string keyName)
        {
            DxBaseValue result = this[keyName];

            if (result != null && result.Type == ValueType.VT_Array)
            {
                return((DxArrayValue)result);
            }
            return(null);
        }
        public void SetInt64(int idx, long value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type != ValueType.VT_Array && v.Type != ValueType.VT_Map)
            {
                arrayList[idx].AsInt64 = value;
                return;
            }
            arrayList[idx] = new DxInt64Value(value);
        }
        public void SetString(int idx, string value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type != ValueType.VT_Array && v.Type != ValueType.VT_Map)
            {
                arrayList[idx].AsString = value;
                return;
            }
            arrayList[idx] = new DxStringValue(value);
        }
        public void SetDateTime(int idx, DateTime value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type == ValueType.VT_DateTime)
            {
                ((DxDateTimeValue)arrayList[idx]).AsDateTime = value;
                return;
            }
            arrayList[idx] = new DxDateTimeValue(value);
        }
        public void SetDouble(int idx, double value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type != ValueType.VT_Array && v.Type != ValueType.VT_Map)
            {
                arrayList[idx].AsDouble = value;
                return;
            }
            arrayList[idx] = new DxDoubleValue(value);
        }
        public void SetFloat(int idx, float value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type != ValueType.VT_Array && v.Type != ValueType.VT_Map)
            {
                arrayList[idx].AsFloat = value;
                return;
            }
            arrayList[idx] = new DxFloatValue(value);
        }
        public void SetBool(int idx, bool value)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type != ValueType.VT_Array && v.Type != ValueType.VT_Map)
            {
                arrayList[idx].AsBoolean = value;
                return;
            }
            arrayList[idx] = new DxBoolValue(value);
        }
        public DxBaseValue this[int idx]
        {
            get
            {
                if (idx >= 0 && idx < arrayList.Count)
                {
                    return(arrayList[idx]);
                }
                return(null);
            }
            set
            {
                idx = ifNilInitArr2idx(idx);
                DxBaseValue v = arrayList[idx];
                if (v != null && v.Type == value.Type)
                {
                    switch (value.Type)
                    {
                    case ValueType.VT_Array:
                        break;

                    case ValueType.VT_Map:
                        break;

                    case ValueType.VT_DateTime:
                        ((DxDateTimeValue)v).AsDateTime = ((DxDateTimeValue)value).AsDateTime;
                        return;

                    case ValueType.VT_Double:
                        v.AsDouble = value.AsDouble;
                        return;

                    case ValueType.VT_Float:
                        v.AsFloat = value.AsFloat;
                        return;

                    case ValueType.VT_Int:
                        v.AsInt = value.AsInt;
                        return;

                    case ValueType.VT_Int64:
                        v.AsInt64 = value.AsInt64;
                        return;

                    case ValueType.VT_String:
                        v.AsString = value.AsString;
                        return;
                    }
                }
                arrayList[idx] = value;
            }
        }
        public override string ToString()
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder(256);
            bool isfirst = true;

            builder.Append('[');
            for (int i = 0; i < arrayList.Count; i++)
            {
                DxBaseValue value = arrayList[i];
                if (isfirst)
                {
                    isfirst = false;
                }
                else
                {
                    builder.Append(',');
                }
                if (value == null)
                {
                    builder.Append("null");
                    continue;
                }
                switch (value.Type)
                {
                case ValueType.VT_Map:
                case ValueType.VT_Array:
                    builder.Append(value.ToString());
                    break;

                case ValueType.VT_Binary:
                    break;

                case ValueType.VT_String:
                case ValueType.VT_DateTime:
                    builder.Append('"');
                    builder.Append(value.AsString);
                    builder.Append('"');
                    break;

                case ValueType.VT_Double:
                case ValueType.VT_Int:
                case ValueType.VT_Int64:
                case ValueType.VT_Boolean:
                    builder.Append(value.AsString);
                    break;
                }
            }
            builder.Append(']');
            return(builder.ToString());
        }
        public void SetBinary(int idx, byte[] bytevalue)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null && v.Type == ValueType.VT_Binary)
            {
                ((DxBinaryValue)v).Bytes = bytevalue;
            }
            else
            {
                DxBinaryValue bv = new DxBinaryValue();
                bv.Bytes       = bytevalue;
                arrayList[idx] = bv;
            }
        }
        public DxValue(object v)
        {
            Type type = v.GetType();

            if (type == typeof(bool))
            {
                value = new DxBoolValue((bool)v);
            }
            else if (type == typeof(int) || type == typeof(uint) || type == typeof(short) || type == typeof(ushort) || type == typeof(byte) || type == typeof(sbyte))
            {
                value = new DxIntValue((int)v);
            }
            else if (type == typeof(long) || type == typeof(ulong))
            {
                value = new DxInt64Value((long)v);
            }
            else if (type == typeof(string))
            {
                value = new DxStringValue((string)v);
            }
            else if (type == typeof(float))
            {
                value = new DxFloatValue((float)v);
            }
            else if (type == typeof(double))
            {
                value = new DxDoubleValue((double)v);
            }
            else if (type == typeof(DateTime))
            {
                value = new DxDateTimeValue((DateTime)v);
            }
            else if (type == typeof(DxBaseValue))
            {
                value = (DxBaseValue)v;
            }
            else if (type == typeof(byte[]))
            {
                DxBinaryValue bv = new DxBinaryValue();
                bv.Bytes = (byte[])v;
            }
        }
 public DateTime GetDateTime(int idx, DateTime defaultvalue)
 {
     if (idx >= 0 && idx < arrayList.Count && arrayList[idx] != null)
     {
         DxBaseValue result = arrayList[idx];
         if (result.Type == ValueType.VT_DateTime)
         {
             return(((DxDateTimeValue)result).AsDateTime);
         }
         else
         {
             string   value = result.AsString;
             DateTime dtv;
             if (DateTime.TryParse(value, out dtv) || DateTime.TryParseExact(value, "yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtv))
             {
                 return(dtv);
             }
         }
     }
     return(defaultvalue);
 }
        public DxArrayValue NewArray(int idx)
        {
            idx = ifNilInitArr2idx(idx);
            DxBaseValue v = arrayList[idx];

            if (v != null)
            {
                switch (v.Type)
                {
                case ValueType.VT_Map:
                    ((DxRecordValue)v).Clear();
                    break;

                case ValueType.VT_Array:
                    return((DxArrayValue)v);
                }
            }
            DxArrayValue result = new DxArrayValue();

            result.parent  = this;
            arrayList[idx] = result;
            return(result);
        }