Beispiel #1
0
        public static object DefaultDictionaryDeserializer(ListTreeNode <T> s)
        {
            switch (s.Value.ValueType)
            {
            case ValueNodeType.Object:
            {
                var u = new Dictionary <string, object>();
                foreach (var kv in s.ObjectItems())
                {
                    //var e = default(object);
                    //kv.Value.Deserialize(ref e);
                    u.Add(kv.Key.GetString(), DefaultDictionaryDeserializer(kv.Value));
                }
                return(u);
            }

            case ValueNodeType.Null:
                return(null);

            case ValueNodeType.Boolean:
                return(s.GetBoolean());

            case ValueNodeType.Integer:
                return(s.GetInt32());

            case ValueNodeType.Number:
                return(s.GetDouble());

            case ValueNodeType.String:
                return(s.GetString());

            default:
                throw new NotImplementedException(s.Value.ValueType.ToString());
            }
        }
        public bool FromJsonSchema(IFileSystemAccessor fs, string key, ListTreeNode <JsonValue> value)
        {
            switch (key)
            {
            case "maxProperties":
                MaxProperties = value.GetInt32();
                return(true);

            case "minProperties":
                MinProperties = value.GetInt32();
                return(true);

            case "required":
            {
                foreach (var req in value.ArrayItems())
                {
                    m_required.Add(req.GetString());
                }
            }
                return(true);

            case "properties":
            {
                foreach (var prop in value.ObjectItems())
                {
                    AddProperty(fs, prop.Key.GetString(), prop.Value);
                }
            }
                return(true);

            case "patternProperties":
                PatternProperties = value.GetString();
                return(true);

            case "additionalProperties":
            {
                var sub = new JsonSchema();
                sub.Parse(fs, value, "additionalProperties");
                AdditionalProperties = sub;
            }
                return(true);

            case "dependencies":
            {
                foreach (var kv in value.ObjectItems())
                {
                    Dependencies.Add(kv.Key.GetString(),
                                     kv.Value.ArrayItems().Select(x => x.GetString()).ToArray());
                }
            }
                return(true);

            case "propertyNames":
                return(true);
            }

            return(false);
        }
        public bool FromJsonSchema(IFileSystemAccessor fs, string key, ListTreeNode <JsonValue> value)
        {
            switch (key)
            {
            case "maxLength":
                MaxLength = value.GetInt32();
                return(true);

            case "minLength":
                MinLength = value.GetInt32();
                return(true);

            case "pattern":
                Pattern = new Regex(value.GetString().Replace("\\\\", "\\"));
                return(true);
            }

            return(false);
        }
 public void Deserialize <T, U>(ListTreeNode <T> src, ref U dst)
     where T : IListTreeItem, IValue <T>
 {
     dst = GenericCast <string, U> .Cast(src.GetString());
 }