示例#1
0
        public JsonEditorHost(object obj, JSchema schema)
        {
            var path = PathUtility.GetTempPath(false);

            this.schemaPath = path + schemaExtension;
            this.Filename   = path + jsonExtension;
            this.type       = obj.GetType();
            this.schema     = schema ?? JsonSchemaUtility.GetSchema(this.type);
            this.schema     = JSchema.Parse(this.schema.ToString());
            this.schema.Properties.Add(schemaKey, JsonSchemaUtility.GetSchema(typeof(string)));

            this.WriteSchemaText();
            this.WriteText(obj);

            this.hash = HashUtility.GetHashValueFromFile(Filename);
        }
示例#2
0
        public override JSchema GetSchema(JSchemaTypeGenerationContext context)
        {
            var definedType  = context.ParentContract.CreatedType;
            var schema       = JsonSchemaUtility.GetSchema(context.ObjectType);
            var propertyInfo = definedType.GetProperty(this.propertyName);

            if (propertyInfo.GetValue(null) is string[] items)
            {
                schema.Enum.Clear();
                foreach (var item in items)
                {
                    schema.Enum.Add(JValue.CreateString(item));
                }
            }
            return(schema);
        }