• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# JTokenType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JTokenType的典型用法代码示例。如果您正苦于以下问题:C# JTokenType类的具体用法?C# JTokenType怎么用?C# JTokenType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JTokenType类属于命名空间,在下文中一共展示了JTokenType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SchemaScope

      public SchemaScope(JTokenType tokenType, IList<JsonSchemaModel> schemas)
      {
        _tokenType = tokenType;
        _schemas = schemas;

        _requiredProperties = schemas.SelectMany<JsonSchemaModel, string>(GetRequiredProperties).Distinct().ToDictionary(p => p, p => false);
      }
开发者ID:pvasek,项目名称:Newtonsoft.Json,代码行数:7,代码来源:JsonValidatingReader.cs


示例2: ValidateMultiValue

 private ValidationResult ValidateMultiValue(string path, IMetadataDefinition definition, JToken token, JTokenType expectedType)
 {
     if (token.Type == JTokenType.Array)
     {
         var array = (JArray)token;
         int index = 0;
         foreach (var item in array)
         {
             if (item.Type != expectedType)
             {
                 return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.UnexpectedItemType, $"Bad metadata: unexpected type '{token.Type.ToString()}' for property {path}[{index}], expected type '{expectedType.ToString()}'.", path);
             }
         }
         return ValidationResult.Success;
     }
     else if (token.Type == JTokenType.Null)
     {
         if (definition.IsRequired)
         {
             return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.FieldRequired, $"Bad metadata: property {path} is required.", path);
         }
         return ValidationResult.Success;
     }
     return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.UnexpectedType, $"Bad metadata: unexpected type '{token.Type.ToString()}' for property {path}, expected type '{nameof(JTokenType.Array)}'.", path);
 }
开发者ID:ansyral,项目名称:docfx,代码行数:25,代码来源:WellknownTypeValidator.cs


示例3: GetNext

 public IEnumerable<JsonData> GetNext(JTokenType type)
 {
     foreach (var token in JsonObject.Children().Where(t => t.Type == type))
     {
         yield return new JsonData(token.ToString());
     }
 }
开发者ID:Dhinoja,项目名称:Arc,代码行数:7,代码来源:JsonData.cs


示例4: SchemaScope

      public SchemaScope(JTokenType tokenType, JsonSchemaModel schema)
      {
        _tokenType = tokenType;
        _schema = schema;

        if (_schema != null && _schema.Properties != null)
          _requiredProperties = GetRequiredProperties(_schema).Distinct().ToDictionary(p => p, p => false);
        else
          _requiredProperties = new Dictionary<string, bool>();
      }
开发者ID:runegri,项目名称:Applicable,代码行数:10,代码来源:JsonValidatingReader.cs


示例5: SchemaScope

            public SchemaScope(JTokenType tokenType, IList<JsonSchemaModel> schemas)
            {
                _tokenType = tokenType;
                _schemas = schemas;

                _requiredProperties = schemas.SelectMany<JsonSchemaModel, string>(GetRequiredProperties).Distinct().ToDictionary(p => p, p => false);

                if (tokenType == JTokenType.Array && schemas.Any(s => s.UniqueItems))
                {
                    IsUniqueArray = true;
                    UniqueArrayItems = new List<JToken>();
                }
            }
开发者ID:nerai,项目名称:nibbler,代码行数:13,代码来源:JsonValidatingReader.cs


示例6: Check

 private static bool Check(JToken jo, string key, JTokenType type, bool isNeedCheck)
 {
     if (!isNeedCheck) return true;
     if (jo[key] == null)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("Error: {0} is Null!", key));
         return false;
     }
     if (jo[key].Type != type)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("Error: {0} should be {1}, not {2}!", key, type, jo[key].Type));
         return false;
     }
     return true;
 }
开发者ID:jovijovi,项目名称:kort,代码行数:15,代码来源:Validator.cs


示例7: ValidateSimpleValue

 private ValidationResult ValidateSimpleValue(string path, IMetadataDefinition definition, JToken token, JTokenType expectedType)
 {
     if (token.Type == expectedType)
     {
         return ValidationResult.Success;
     }
     if (token.Type == JTokenType.Null)
     {
         if (definition.IsRequired)
         {
             return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.FieldRequired, $"Bad metadata: property {path} is required.", path);
         }
         return ValidationResult.Success;
     }
     return ValidationResult.Fail(ValidationErrorCodes.WellknownMetadata.UnexpectedType, $"Bad metadata: unexpected type '{token.Type.ToString()}' for property {path}, expected type '{expectedType.ToString()}'.", path);
 }
开发者ID:ansyral,项目名称:docfx,代码行数:16,代码来源:WellknownTypeValidator.cs


示例8: FromJsonType

        public static DbType FromJsonType(JTokenType type)
        {
            if (type == JTokenType.String) {
                return DbType.Varchar;
            }

            if (type == JTokenType.Float) {
                return DbType.Float;
            }

            if (type == JTokenType.Integer) {
                return DbType.Integer;
            }
            if (type == JTokenType.Date) {
                return DbType.DateTime;
            }
            if (type == JTokenType.Boolean) {
                return DbType.Bit;
            }
            return DbType.Unknown;
        }
开发者ID:GrowingData,项目名称:Mung,代码行数:21,代码来源:DbType.cs


示例9: SerializeValue

        public static object SerializeValue(JToken value, string storeType, JTokenType columnType)
        {
            if (value == null || value.Type == JTokenType.Null)
            {
                return null;
            }

            if (IsTextType(storeType))
            {
                return SerializeAsText(value, columnType);
            }
            if (IsRealType(storeType))
            {
                return SerializeAsReal(value, columnType);
            }
            if (IsNumberType(storeType))
            {
                return SerializeAsNumber(value, columnType);
            }

            return value.ToString();
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:22,代码来源:SqlHelpers.cs


示例10: DeserializeValue

        public static JToken DeserializeValue(object value, string storeType, JTokenType columnType)
        {
            if (value == null)
            {
                return null;
            }

            if (IsTextType(storeType))
            {
                return SqlHelpers.ParseText(columnType, value);
            }
            if (IsRealType(storeType))
            {
                return SqlHelpers.ParseReal(columnType, value);
            }
            if (IsNumberType(storeType))
            {
                return SqlHelpers.ParseNumber(columnType, value);
            }

            return null;
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:22,代码来源:SqlHelpers.cs


示例11: GetColumnType

        public static string GetColumnType(JTokenType type, bool allowNull)
        {
            switch (type)
            {
                case JTokenType.Boolean:
                    return SqlColumnType.Bit;
                case JTokenType.Integer:
                    return SqlColumnType.BigInt;
                case JTokenType.Date:
                    return SqlColumnType.DateTime;
                case JTokenType.Float:
                    return SqlColumnType.Double;
                case JTokenType.Guid:
                    return SqlColumnType.UniqueIdentifier;
                case JTokenType.String:
                case JTokenType.Array:
                case JTokenType.Object:
                    return SqlColumnType.NVarcharMax;
                case JTokenType.Bytes:
                    return SqlColumnType.VarBinaryMax;
                case JTokenType.Null:
                    if (allowNull)
                    {
                        return null;
                    }
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.SqlStore_JTokenNotSupported, type));
                case JTokenType.Comment:
                case JTokenType.Constructor:
                case JTokenType.None:
                case JTokenType.Property:
                case JTokenType.Raw:
                case JTokenType.TimeSpan:
                case JTokenType.Undefined:
                case JTokenType.Uri:
                default:
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.SqlStore_JTokenNotSupported, type));

            }
        }
开发者ID:dpcons,项目名称:ZumoContrib,代码行数:39,代码来源:SqlHelpers.cs


示例12: GetTypeFromJTokenType

 /// <summary>
 /// Gets the .NET type from JTokenType.
 /// </summary>
 /// <param name="jt">The JTokenType to convert</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException">support for  + jt +  is not implemented.</exception>
 private static string GetTypeFromJTokenType(JTokenType jt)
 {
     switch (jt)
     {
         case JTokenType.TimeSpan:
         case JTokenType.Uri:
         case JTokenType.Boolean:
         case JTokenType.Guid:
         case JTokenType.String:
             return jt.ToString();
         case JTokenType.Bytes:
             return "byte[]";
         case JTokenType.Date:
             return "DateTime";
         case JTokenType.Float:
             return "double";
         case JTokenType.Integer:
             return "int";
         case JTokenType.Null:
             return "String";
         default:
             throw new NotImplementedException("support for " + jt + " is not implemented.");
     }
 }
开发者ID:aulsai,项目名称:NancyBlack,代码行数:30,代码来源:DataProperty.cs


示例13: Push

 private void Push(JTokenType value)
 {
   _stack.Add(value);
   _top++;
   _currentTypeContext = value;
 }
开发者ID:GregLukosek,项目名称:Crowd,代码行数:6,代码来源:JsonReader.cs


示例14: SchemaScope

 public SchemaScope(JTokenType tokenType, IList<JsonSchemaModel> schemas)
 {
   this._tokenType = tokenType;
   this._schemas = schemas;
   this._requiredProperties = Enumerable.ToDictionary<string, string, bool>(Enumerable.Distinct<string>(Enumerable.SelectMany<JsonSchemaModel, string>((IEnumerable<JsonSchemaModel>) schemas, new Func<JsonSchemaModel, IEnumerable<string>>(this.GetRequiredProperties))), (Func<string, string>) (p => p), (Func<string, bool>) (p => false));
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:6,代码来源:JsonValidatingReader.cs


示例15: GetValueType

        private static JTokenType GetValueType(JTokenType? current, object value)
        {
            if (value == null)
            return JTokenType.Null;
              else if (value is string)
            return GetStringValueType(current);
              else if (value is long || value is int || value is short || value is sbyte
            || value is ulong || value is uint || value is ushort || value is byte)
            return JTokenType.Integer;
              else if (value is double || value is float || value is decimal)
            return JTokenType.Float;
              else if (value is DateTime)
            return JTokenType.Date;
              else if (value is DateTimeOffset)
            return JTokenType.Date;
              else if (value is bool)
            return JTokenType.Boolean;

              throw new ArgumentException("Could not determin JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:20,代码来源:JValue.cs


示例16: GetStringValueType

        private static JTokenType GetStringValueType(JTokenType? current)
        {
            if (current == null)
            return JTokenType.String;

              switch (current.Value)
              {
            case JTokenType.Comment:
            case JTokenType.String:
            case JTokenType.Raw:
              return current.Value;
            default:
              return JTokenType.String;
              }
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:15,代码来源:JValue.cs


示例17: JValue

 internal JValue(object value, JTokenType type)
 {
     _value = value;
       _valueType = type;
 }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:5,代码来源:JValue.cs


示例18: SerializeAsInteger

 private static long SerializeAsInteger(JToken value, JTokenType columnType)
 {
     return value.Value<long>();
 }
开发者ID:dpcons,项目名称:ZumoContrib,代码行数:4,代码来源:SqlHelpers.cs


示例19: GetCloseTokenForType

 private JsonToken GetCloseTokenForType(JTokenType type)
 {
   switch (type)
   {
     case JTokenType.Object:
       return JsonToken.EndObject;
     case JTokenType.Array:
       return JsonToken.EndArray;
     case JTokenType.Constructor:
       return JsonToken.EndConstructor;
     default:
       throw new JsonWriterException("No close token for type: " + type);
   }
 }
开发者ID:Epiphane,项目名称:GGJ2016,代码行数:14,代码来源:JsonWriter.cs


示例20: WriteValueElement

 private void WriteValueElement(JTokenType type)
 {
     if (_propertyName != null)
     {
         WriteValueElement(_propertyName, type);
         _propertyName = null;
     }
     else
     {
         WriteValueElement("Item", type);
     }
 }
开发者ID:ZhouAnPing,项目名称:Mail,代码行数:12,代码来源:CustomJsonWriter.cs



注:本文中的JTokenType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JValue类代码示例发布时间:2022-05-24
下一篇:
C# JToken类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap