当前位置: 首页>>代码示例>>C#>>正文


C# JTokenType.ToString方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: WriteValueElement

 private void WriteValueElement(string elementName, JTokenType type)
 {
     _writer.WriteStartElement(elementName);
     _writer.WriteAttributeString("type", type.ToString());
 }
开发者ID:ZhouAnPing,项目名称:Mail,代码行数:5,代码来源:CustomJsonWriter.cs


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