本文整理汇总了C#中JTokenType类的典型用法代码示例。如果您正苦于以下问题:C# JTokenType类的具体用法?C# JTokenType怎么用?C# JTokenType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JTokenType类属于命名空间,在下文中一共展示了JTokenType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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());
}
}
示例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>();
}
示例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>();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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));
}
}
示例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.");
}
}
示例13: Push
private void Push(JTokenType value)
{
_stack.Add(value);
_top++;
_currentTypeContext = value;
}
示例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));
}
示例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()));
}