本文整理汇总了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);
}
示例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);
}
示例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.");
}
}
示例4: WriteValueElement
private void WriteValueElement(string elementName, JTokenType type)
{
_writer.WriteStartElement(elementName);
_writer.WriteAttributeString("type", type.ToString());
}