當前位置: 首頁>>代碼示例>>C#>>正文


C# Schema.JsonSchema類代碼示例

本文整理匯總了C#中Newtonsoft.Json.Schema.JsonSchema的典型用法代碼示例。如果您正苦於以下問題:C# JsonSchema類的具體用法?C# JsonSchema怎麽用?C# JsonSchema使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonSchema類屬於Newtonsoft.Json.Schema命名空間,在下文中一共展示了JsonSchema類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsValid

 public static bool IsValid(this JToken source, JsonSchema schema, out IList<string> errorMessages)
 {
   IList<string> errors = (IList<string>) new List<string>();
   Extensions.Validate(source, schema, (ValidationEventHandler) ((sender, args) => errors.Add(args.Message)));
   errorMessages = errors;
   return errorMessages.Count == 0;
 }
開發者ID:tanis2000,項目名稱:FEZ,代碼行數:7,代碼來源:Extensions.cs

示例2: Push

 private void Push(JsonSchema value)
 {
   _currentSchema = value;
   _stack.Add(value);
   _resolver.LoadedSchemas.Add(value);
   _documentSchemas.Add(value.Location, value);
 }
開發者ID:GCC-Autobahn,項目名稱:Newtonsoft.Json,代碼行數:7,代碼來源:JsonSchemaBuilder.cs

示例3: AddProperty

        public void AddProperty(IDictionary<string, JsonSchemaNode> target, string propertyName, JsonSchema schema)
        {
            JsonSchemaNode propertyNode;
            target.TryGetValue(propertyName, out propertyNode);

            target[propertyName] = AddSchema(propertyNode, schema);
        }
開發者ID:ThePiachu,項目名稱:BitNet,代碼行數:7,代碼來源:JsonSchemaModelBuilder.cs

示例4: Build

 public JsonSchemaModel Build(JsonSchema schema)
 {
   this._nodes = new JsonSchemaNodeCollection();
   this._node = this.AddSchema((JsonSchemaNode) null, schema);
   this._nodeModels = new Dictionary<JsonSchemaNode, JsonSchemaModel>();
   return this.BuildNodeModel(this._node);
 }
開發者ID:Zeludon,項目名稱:FEZ,代碼行數:7,代碼來源:JsonSchemaModelBuilder.cs

示例5: GetCodeType

        /// <summary>
        /// Returns a code type references for the specified json schema.
        /// Generates the appropriate references.
        /// </summary>
        internal static CodeTypeReference GetCodeType(JsonSchema propertySchema,
                                                      SchemaImplementationDetails details,
                                                      INestedClassProvider internalClassProvider)
        {
            propertySchema.ThrowIfNull("propertySchema");
            internalClassProvider.ThrowIfNull("internalClassProvider");
            if (propertySchema.Type.HasValue == false)
            {
                throw new NotSupportedException("propertySchema has no Type. " + propertySchema);
            }

            switch (propertySchema.Type.Value)
            {
                case JsonSchemaType.String:
                    return new CodeTypeReference(typeof(string));
                case JsonSchemaType.Integer:
                    return new CodeTypeReference(typeof(long?));
                case JsonSchemaType.Boolean:
                    return new CodeTypeReference(typeof(bool?));
                case JsonSchemaType.Float:
                    return new CodeTypeReference(typeof(double?));
                case JsonSchemaType.Array:
                    return GetArrayTypeReference(propertySchema, details, internalClassProvider);
                case JsonSchemaType.Object:
                    return GetObjectTypeReference(propertySchema, details, internalClassProvider);
                case JsonSchemaType.Any:
                    return new CodeTypeReference(typeof(string));
                default:
                    logger.Warning(
                        "Found currently unsupported type {0} as part of {1}", propertySchema.Type.Value,
                        propertySchema);
                    return new CodeTypeReference(typeof(object));
            }
        }
開發者ID:JANCARLO123,項目名稱:google-apis,代碼行數:38,代碼來源:SchemaDecoratorUtil.cs

示例6: AddSchema

        public JsonSchemaNode AddSchema(JsonSchemaNode existingNode, JsonSchema schema)
        {
            string newId;
            if (existingNode != null)
            {
                if (existingNode.Schemas.Contains(schema))
                {
                    return existingNode;
                }

                newId = JsonSchemaNode.GetId(existingNode.Schemas.Union(new[] { schema }));
            }
            else
            {
                newId = JsonSchemaNode.GetId(new[] { schema });
            }

            if (_nodes.Contains(newId))
            {
                return _nodes[newId];
            }

            JsonSchemaNode currentNode = (existingNode != null)
                ? existingNode.Combine(schema)
                : new JsonSchemaNode(schema);

            _nodes.Add(currentNode);

            AddProperties(schema.Properties, currentNode.Properties);

            AddProperties(schema.PatternProperties, currentNode.PatternProperties);

            if (schema.Items != null)
            {
                for (int i = 0; i < schema.Items.Count; i++)
                {
                    AddItem(currentNode, i, schema.Items[i]);
                }
            }

            if (schema.AdditionalItems != null)
            {
                AddAdditionalItems(currentNode, schema.AdditionalItems);
            }

            if (schema.AdditionalProperties != null)
            {
                AddAdditionalProperties(currentNode, schema.AdditionalProperties);
            }

            if (schema.Extends != null)
            {
                foreach (JsonSchema jsonSchema in schema.Extends)
                {
                    currentNode = AddSchema(currentNode, jsonSchema);
                }
            }

            return currentNode;
        }
開發者ID:Chunshan-Theta,項目名稱:Xamarin_WeatherAPP_iOS_Android-,代碼行數:60,代碼來源:JsonSchemaModelBuilder.cs

示例7: AsMarkdown

        /// <summary>
        ///     轉化為markdown格式。
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static string AsMarkdown(JsonSchema schema)
        {
            var sb = new StringBuilder();

            // 生成表格
            sb.AppendLine(AsMarkdown(schema, 1).Trim());

            // 生成例子
            sb.AppendLine();
            sb.AppendLine("例子");
            sb.AppendLine();

            JToken demoToken = JsonDemoGenerator.Generate(schema);
            string demo = JsonConvert.SerializeObject(demoToken, Formatting.Indented);

            // 每一行前+4個空格,以適應markdown的code格式。
            var sr = new StringReader(demo);
            string line = sr.ReadLine();
            while (!string.IsNullOrEmpty(line))
            {
                sb.AppendLine("    " + line);
                line = sr.ReadLine();
            }

            return sb.ToString();
        }
開發者ID:JohnnyFee,項目名稱:JsonDoc,代碼行數:31,代碼來源:JsonDocFormatter.cs

示例8: Combine

    private static void Combine(JsonSchemaModel model, JsonSchema schema)
    {
      model.Optional = model.Optional && (schema.Optional ?? false);
      model.Type = model.Type & (schema.Type ?? JsonSchemaType.Any);

      model.MinimumLength = MathUtils.Max(model.MinimumLength, schema.MinimumLength);
      model.MaximumLength = MathUtils.Min(model.MaximumLength, schema.MaximumLength);
      model.MaximumDecimals = MathUtils.Min(model.MaximumDecimals, schema.MaximumDecimals);
      model.Minimum = MathUtils.Max(model.Minimum, schema.Minimum);
      model.Maximum = MathUtils.Max(model.Maximum, schema.Maximum);
      model.MinimumItems = MathUtils.Max(model.MinimumItems, schema.MinimumItems);
      model.MaximumItems = MathUtils.Min(model.MaximumItems, schema.MaximumItems);
      model.AllowAdditionalProperties = model.AllowAdditionalProperties && schema.AllowAdditionalProperties;
      if (schema.Enum != null)
      {
        if (model.Enum == null)
          model.Enum = new List<JToken>();

        model.Enum.AddRangeDistinct(schema.Enum, new JTokenEqualityComparer());
      }
      model.Disallow = model.Disallow | (schema.Disallow ?? JsonSchemaType.None);

      if (schema.Pattern != null)
      {
        if (model.Patterns == null)
          model.Patterns = new List<string>();

        model.Patterns.AddDistinct(schema.Pattern);
      }
    }
開發者ID:runegri,項目名稱:Applicable,代碼行數:30,代碼來源:JsonSchemaModel.cs

示例9: GenerateAllProperties

        internal IList<CodeMemberProperty> GenerateAllProperties(string name,
            JsonSchema schema,
            IDictionary<JsonSchema, SchemaImplementationDetails>
            implDetails,
            INestedClassProvider internalClassProvider,
            params string[] usedWordsInContext)
        {
            schema.ThrowIfNull("schema");
            name.ThrowIfNullOrEmpty("name");
            logger.Debug("Adding properties for {0}", name);

            var fields = new List<CodeMemberProperty>();

            if (schema.Properties.IsNullOrEmpty())
            {
                logger.Debug("No properties found for schema " + name);
                return fields;
            }

            IEnumerable<string> allUsedWordsInContext = usedWordsInContext.Concat(schema.Properties.Keys);
            int index = 0;
            foreach (var propertyPair in schema.Properties)
            {
                SchemaImplementationDetails details = implDetails[propertyPair.Value];

                CodeMemberProperty property = GenerateProperty(
                    propertyPair.Key, propertyPair.Value, details, index++, internalClassProvider,
                    allUsedWordsInContext.Except(new[] { propertyPair.Key }));
                fields.Add(property);
            }
            return fields;
        }
開發者ID:nick0816,項目名稱:LoggenCSG,代碼行數:32,代碼來源:StandardPropertyDecorator.cs

示例10: CreateInstanceFromSchema

    protected string CreateInstanceFromSchema(JsonSchema schema, int indent)
    {
      if (schema.Type == JsonSchemaType.Array)
      {
        var items = schema.Items != null
          ? schema.Items.Select(i => CreateInstanceFromSchema(i, indent+1))
          : Enumerable.Empty<string>();
        return Indent(indent) + "[\n" + string.Join(",\n", items) + Indent(indent) + "]\n";
      }

      if (schema.Type == JsonSchemaType.Object || schema.Type == null)
      {
        var properties = schema.Properties != null
          ? schema.Properties.Select(i => CreateInstanceFromProperty(i, indent+1))
          : Enumerable.Empty<string>();
        return Indent(indent) + "{\n" + string.Join(",\n", properties) + "\n" + Indent(indent) + "}\n";
      }

      if (schema.Type == JsonSchemaType.String)
      {
        return Indent(indent) + "\"\"";
      }

      if (schema.Type == JsonSchemaType.Integer)
      {
        return Indent(indent) + "0";
      }

      if (schema.Type == JsonSchemaType.Boolean)
      {
        return Indent(indent) + "false";
      }

      return "";
    }
開發者ID:paulswartz,項目名稱:Mason,代碼行數:35,代碼來源:JsonExampleGenerator.cs

示例11: AddSchema

 public JsonSchemaNode AddSchema(JsonSchemaNode existingNode, JsonSchema schema)
 {
   string id;
   if (existingNode != null)
   {
     if (existingNode.Schemas.Contains(schema))
       return existingNode;
     id = JsonSchemaNode.GetId(Enumerable.Union<JsonSchema>((IEnumerable<JsonSchema>) existingNode.Schemas, (IEnumerable<JsonSchema>) new JsonSchema[1]
     {
       schema
     }));
   }
   else
     id = JsonSchemaNode.GetId((IEnumerable<JsonSchema>) new JsonSchema[1]
     {
       schema
     });
   if (this._nodes.Contains(id))
     return this._nodes[id];
   JsonSchemaNode jsonSchemaNode = existingNode != null ? existingNode.Combine(schema) : new JsonSchemaNode(schema);
   this._nodes.Add(jsonSchemaNode);
   this.AddProperties(schema.Properties, (IDictionary<string, JsonSchemaNode>) jsonSchemaNode.Properties);
   this.AddProperties(schema.PatternProperties, (IDictionary<string, JsonSchemaNode>) jsonSchemaNode.PatternProperties);
   if (schema.Items != null)
   {
     for (int index = 0; index < schema.Items.Count; ++index)
       this.AddItem(jsonSchemaNode, index, schema.Items[index]);
   }
   if (schema.AdditionalProperties != null)
     this.AddAdditionalProperties(jsonSchemaNode, schema.AdditionalProperties);
   if (schema.Extends != null)
     jsonSchemaNode = this.AddSchema(jsonSchemaNode, schema.Extends);
   return jsonSchemaNode;
 }
開發者ID:Zeludon,項目名稱:FEZ,代碼行數:34,代碼來源:JsonSchemaModelBuilder.cs

示例12: GetArrayTypeReference

        internal static CodeTypeReference GetArrayTypeReference(JsonSchema propertySchema,
                                                                 SchemaImplementationDetails details,
                                                                 INestedClassProvider internalClassProvider)
        {
            propertySchema.ThrowIfNull("propertySchema");
            if (propertySchema.Type != JsonSchemaType.Array)
            {
                throw new ArgumentException("Must be of JsonSchemaType.Array", "propertySchema");
            }

            var arrayItems = propertySchema.Items;
            if (arrayItems != null && arrayItems.Count == 1)
            {
                CodeTypeReference itemType = arrayItems[0].Id.IsNotNullOrEmpty()
                    ? new CodeTypeReference(arrayItems[0].Id)
                    : GetCodeType(arrayItems[0], details, internalClassProvider);
                logger.Debug("type for array {0}", itemType.BaseType);
                return new CodeTypeReference(typeof(IList<>))
                {
                    TypeArguments = { itemType }
                };
            }

            logger.Warning("Found Array of unhandled type. {0}", propertySchema);
            return new CodeTypeReference(typeof(System.Collections.IList));
        }
開發者ID:JANCARLO123,項目名稱:google-apis,代碼行數:26,代碼來源:SchemaDecoratorUtil.cs

示例13: GenerateAllFields

        internal IList<CodeMemberField> GenerateAllFields(string name,
                                                          JsonSchema schema,
                                                          IDictionary<JsonSchema, SchemaImplementationDetails>
                                                              implDetails,
                                                          INestedClassProvider internalClassProvider)
        {
            schema.ThrowIfNull("schema");
            name.ThrowIfNull("name");
            implDetails.ThrowIfNull("details");
            internalClassProvider.ThrowIfNull("internalClassProvider");

            var fields = new List<CodeMemberField>();
            if (schema.Properties.IsNullOrEmpty())
            {
                logger.Debug("No Properties found for " + name);
                return fields;
            }

            int index = 0;
            foreach (var propertyPair in schema.Properties)
            {
                SchemaImplementationDetails details = implDetails[propertyPair.Value];

                fields.Add(
                    GenerateField(
                        propertyPair.Key, propertyPair.Value, details, index, internalClassProvider,
                        schema.Properties.Keys.Without(propertyPair.Key)));
                index++;
            }
            return fields;
        }
開發者ID:JANCARLO123,項目名稱:google-apis,代碼行數:31,代碼來源:StandardPropertyFieldDecorator.cs

示例14: Pop

 private JsonSchema Pop()
 {
   JsonSchema jsonSchema = this._currentSchema;
   this._stack.RemoveAt(this._stack.Count - 1);
   this._currentSchema = Enumerable.LastOrDefault<JsonSchema>((IEnumerable<JsonSchema>) this._stack);
   return jsonSchema;
 }
開發者ID:Zeludon,項目名稱:FEZ,代碼行數:7,代碼來源:JsonSchemaBuilder.cs

示例15: AddProperty

        public void AddProperty(JsonSchemaNode parentNode, string propertyName, JsonSchema schema)
        {
            JsonSchemaNode propertyNode;
              parentNode.Properties.TryGetValue(propertyName, out propertyNode);

              parentNode.Properties[propertyName] = AddSchema(propertyNode, schema);
        }
開發者ID:anukat2015,項目名稱:sones,代碼行數:7,代碼來源:JsonSchemaModelBuilder.cs


注:本文中的Newtonsoft.Json.Schema.JsonSchema類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。