本文整理汇总了C#中JsonSchemaType类的典型用法代码示例。如果您正苦于以下问题:C# JsonSchemaType类的具体用法?C# JsonSchemaType怎么用?C# JsonSchemaType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonSchemaType类属于命名空间,在下文中一共展示了JsonSchemaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestType
private bool TestType(JsonSchemaModel currentSchema, JsonSchemaType currentType)
{
if (!JsonSchemaGenerator.HasFlag(currentSchema.Type, currentType))
{
RaiseError("Invalid type. Expected {0} but got {1}.".FormatWith(CultureInfo.InvariantCulture, currentSchema.Type, currentType), currentSchema);
return false;
}
return true;
}
示例2: AddNullType
private JsonSchemaType AddNullType(JsonSchemaType type, Required valueRequired)
{
if (valueRequired != Required.Always)
return type | JsonSchemaType.Null;
return type;
}
示例3: HasFlag
internal static bool HasFlag(JsonSchemaType? value, JsonSchemaType flag)
{
// default value is Any
if (value == null)
return true;
return ((value & flag) == flag);
}
示例4: MapType
internal static string MapType(JsonSchemaType type)
{
return JsonSchemaConstants.JsonSchemaTypeMapping.Single(kv => kv.Value == type).Key;
}
示例5: MapType
internal static string MapType(JsonSchemaType type)
{
return Enumerable.Single<KeyValuePair<string, JsonSchemaType>>((IEnumerable<KeyValuePair<string, JsonSchemaType>>) JsonSchemaConstants.JsonSchemaTypeMapping, (Func<KeyValuePair<string, JsonSchemaType>, bool>) (kv => kv.Value == type)).Key;
}
示例6: TestType
private bool TestType(JsonSchemaModel currentSchema, JsonSchemaType currentType)
{
if (JsonSchemaGenerator.HasFlag(new JsonSchemaType?(currentSchema.Type), currentType))
return true;
this.RaiseError(StringUtils.FormatWith("Invalid type. Expected {0} but got {1}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) currentSchema.Type, (object) currentType), currentSchema);
return false;
}
示例7: Map
public static string Map(JsonSchemaType? type)
{
return type == null || !typeConversion.ContainsKey(type.Value) ? null : typeConversion[type.Value];
}
示例8: GetPrimitiveTypeAsString
/// <summary>
/// Get the primitive name of a type if it exists.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>The primitive type as a string, if it exists.</returns>
public static string GetPrimitiveTypeAsString(JsonSchemaType? type)
{
string sType = type.ToString();
return Primitives.ContainsKey(sType) ? Primitives[sType] : "System.Object";
}
示例9: JsonSchemaTypesToLabel
private static string JsonSchemaTypesToLabel(JsonSchemaType type)
{
var types = new string[6];
int index = 0;
if ((type & JsonSchemaType.String) == JsonSchemaType.String)
types[index++] = "string";
if ((type & JsonSchemaType.Float) == JsonSchemaType.Float || (type & JsonSchemaType.Integer) == JsonSchemaType.Integer)
types[index++] = "number";
if ((type & JsonSchemaType.Boolean) == JsonSchemaType.Boolean)
types[index++] = "boolean";
if ((type & JsonSchemaType.Object) == JsonSchemaType.Object)
types[index++] = "object";
if ((type & JsonSchemaType.Array) == JsonSchemaType.Array)
types[index++] = "array";
if ((type & JsonSchemaType.Null) == JsonSchemaType.Null)
types[index++] = "null";
switch (index)
{
case 0:
return "";
case 1:
return types[0];
case 2:
return types[0] + " or " + types[1];
default:
return string.Join(", ", types, 0, index - 1) + ", or " + types[index - 1];
}
}
示例10: WriteType
// Token: 0x06000A0F RID: 2575
// RVA: 0x0003F7F8 File Offset: 0x0003D9F8
private void WriteType(string propertyName, JsonWriter writer, JsonSchemaType type)
{
IList<JsonSchemaType> list;
if (Enum.IsDefined(typeof(JsonSchemaType), type))
{
list = new List<JsonSchemaType>
{
type
};
}
else
{
list = Enumerable.ToList<JsonSchemaType>(Enumerable.Where<JsonSchemaType>(EnumUtils.GetFlagsValues<JsonSchemaType>(type), (JsonSchemaType v) => v != JsonSchemaType.None));
}
if (list.Count == 0)
{
return;
}
writer.WritePropertyName(propertyName);
if (list.Count == 1)
{
writer.WriteValue(JsonSchemaBuilder.MapType(list[0]));
return;
}
writer.WriteStartArray();
foreach (JsonSchemaType current in list)
{
writer.WriteValue(JsonSchemaBuilder.MapType(current));
}
writer.WriteEndArray();
}
示例11: WriteType
private void WriteType(string propertyName, JsonWriter writer, JsonSchemaType type)
{
IList<JsonSchemaType> list;
if (Enum.IsDefined(typeof (JsonSchemaType), (object) type))
list = (IList<JsonSchemaType>) new List<JsonSchemaType>()
{
type
};
else
list = (IList<JsonSchemaType>) Enumerable.ToList<JsonSchemaType>(Enumerable.Where<JsonSchemaType>((IEnumerable<JsonSchemaType>) EnumUtils.GetFlagsValues<JsonSchemaType>(type), (Func<JsonSchemaType, bool>) (v => v != JsonSchemaType.None)));
if (list.Count == 0)
return;
writer.WritePropertyName(propertyName);
if (list.Count == 1)
{
writer.WriteValue(JsonSchemaBuilder.MapType(list[0]));
}
else
{
writer.WriteStartArray();
foreach (JsonSchemaType type1 in (IEnumerable<JsonSchemaType>) list)
writer.WriteValue(JsonSchemaBuilder.MapType(type1));
writer.WriteEndArray();
}
}
示例12: MapType
// Token: 0x06000B75 RID: 2933
// RVA: 0x00042A00 File Offset: 0x00040C00
internal static string MapType(JsonSchemaType type)
{
return Enumerable.Single<KeyValuePair<string, JsonSchemaType>>(JsonSchemaConstants.JsonSchemaTypeMapping, (KeyValuePair<string, JsonSchemaType> kv) => kv.Value == type).Key;
}
示例13: HasFlag
// Token: 0x06000B8C RID: 2956
// RVA: 0x000431E0 File Offset: 0x000413E0
internal static bool HasFlag(JsonSchemaType? value, JsonSchemaType flag)
{
return !value.HasValue || (value & flag) == flag || (flag == JsonSchemaType.Integer && (value & JsonSchemaType.Float) == JsonSchemaType.Float);
}
示例14: HasFlag
internal static bool HasFlag(JsonSchemaType? value, JsonSchemaType flag)
{
// default value is Any
if (value == null)
return true;
bool match = ((value & flag) == flag);
if (match)
return true;
// integer is a subset of float
if (value == JsonSchemaType.Float && flag == JsonSchemaType.Integer)
return true;
return false;
}
示例15: JsonSchemaTypesToLabel
private string JsonSchemaTypesToLabel(JsonSchemaType type)
{
var types = new string[6];
int index = 0;
if ((type & JsonSchemaType.String) == JsonSchemaType.String)
types[index++] = "string";
if ((type & JsonSchemaType.Float) == JsonSchemaType.Float || (type & JsonSchemaType.Integer) == JsonSchemaType.Integer)
types[index++] = "number";
if ((type & JsonSchemaType.Boolean) == JsonSchemaType.Boolean)
types[index++] = "boolean";
if ((type & JsonSchemaType.Object) == JsonSchemaType.Object)
types[index++] = "object";
if ((type & JsonSchemaType.Array) == JsonSchemaType.Array)
types[index++] = "array";
if ((type & JsonSchemaType.Null) == JsonSchemaType.Null)
types[index++] = "null";
if (index == 0)
return "";
else if (index == 1)
return types[0];
else if (index == 2)
return types[0] + " or " + types[1];
else
return String.Join(", ", types, 0, index - 1) + ", or " + types[index - 1];
}