/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Comoros); }
/// <summary> /// Convert <see cref="Iran.EnumValues"/> to region code likes 'DE', 'WAL'. /// </summary> /// <param name="values"></param> /// <returns></returns> public static string ToRegionCode(this EnumValues values) { return(values.GetAttr <EnumValues, AliasInShortAttribute>().Alias); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Eritrea); }
static bool TryParseEnum <TEnum>(string asStr, out TEnum parsed) where TEnum : struct { return(EnumValues <TEnum> .TryParse(asStr, out parsed)); }
/// <summary> /// Get Cosmos Region Code / CEP-1 from the given enum values. /// </summary> /// <param name="value"></param> /// <returns></returns> public static RegionCodeValue GetRegionCodeValue(this EnumValues value) { return((RegionCodeValue)value.ToNumericRegionCode()); }
public static bool IsUnknownValue(this EnumValues value) => EnumValues.Unknown == value;
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Vanuatu); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Iran); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Singapore); }
private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required) { ValidationUtils.ArgumentNotNull(type, "type"); string resolvedId = GetTypeId(type, false); string explicitId = GetTypeId(type, true); if (!string.IsNullOrEmpty(resolvedId)) { JsonSchema resolvedSchema = _resolver.GetSchema(resolvedId); if (resolvedSchema != null) { // resolved schema is not null but referencing member allows nulls // change resolved schema to allow nulls. hacky but what are ya gonna do? if (valueRequired != Required.Always && !HasFlag(resolvedSchema.Type, JsonSchemaType.Null)) { resolvedSchema.Type |= JsonSchemaType.Null; } if (required && resolvedSchema.Required != true) { resolvedSchema.Required = true; } return(resolvedSchema); } } // test for unresolved circular reference if (_stack.Any(tc => tc.Type == type)) { throw new JsonException("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".FormatWith(CultureInfo.InvariantCulture, type)); } JsonContract contract = ContractResolver.ResolveContract(type); JsonConverter converter; if ((converter = contract.Converter) != null || (converter = contract.InternalConverter) != null) { JsonSchema converterSchema = converter.GetSchema(); if (converterSchema != null) { return(converterSchema); } } Push(new TypeSchema(type, new JsonSchema())); if (explicitId != null) { CurrentSchema.Id = explicitId; } if (required) { CurrentSchema.Required = true; } CurrentSchema.Title = GetTitle(type); CurrentSchema.Description = GetDescription(type); if (converter != null) { // todo: Add GetSchema to JsonConverter and use here? CurrentSchema.Type = JsonSchemaType.Any; } else { switch (contract.ContractType) { case JsonContractType.Object: CurrentSchema.Type = AddNullType(JsonSchemaType.Object, valueRequired); CurrentSchema.Id = GetTypeId(type, false); GenerateObjectSchema(type, (JsonObjectContract)contract); break; case JsonContractType.Array: CurrentSchema.Type = AddNullType(JsonSchemaType.Array, valueRequired); CurrentSchema.Id = GetTypeId(type, false); JsonArrayAttribute arrayAttribute = JsonTypeReflector.GetJsonContainerAttribute(type) as JsonArrayAttribute; bool allowNullItem = (arrayAttribute == null || arrayAttribute.AllowNullItems); Type collectionItemType = ReflectionUtils.GetCollectionItemType(type); if (collectionItemType != null) { CurrentSchema.Items = new List <JsonSchema>(); CurrentSchema.Items.Add(GenerateInternal(collectionItemType, (!allowNullItem) ? Required.Always : Required.Default, false)); } break; case JsonContractType.Primitive: CurrentSchema.Type = GetJsonSchemaType(type, valueRequired); if (CurrentSchema.Type == JsonSchemaType.Integer && type.IsEnum() && !type.IsDefined(typeof(FlagsAttribute), true)) { CurrentSchema.Enum = new List <JToken>(); EnumValues <long> enumValues = EnumUtils.GetNamesAndValues <long>(type); foreach (EnumValue <long> enumValue in enumValues) { JToken value = JToken.FromObject(enumValue.Value); CurrentSchema.Enum.Add(value); } } break; case JsonContractType.String: JsonSchemaType schemaType = (!ReflectionUtils.IsNullable(contract.UnderlyingType)) ? JsonSchemaType.String : AddNullType(JsonSchemaType.String, valueRequired); CurrentSchema.Type = schemaType; break; case JsonContractType.Dictionary: CurrentSchema.Type = AddNullType(JsonSchemaType.Object, valueRequired); Type keyType; Type valueType; ReflectionUtils.GetDictionaryKeyValueTypes(type, out keyType, out valueType); if (keyType != null) { JsonContract keyContract = ContractResolver.ResolveContract(keyType); // can be converted to a string if (keyContract.ContractType == JsonContractType.Primitive) { CurrentSchema.AdditionalProperties = GenerateInternal(valueType, Required.Default, false); } } break; #if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40) case JsonContractType.Serializable: CurrentSchema.Type = AddNullType(JsonSchemaType.Object, valueRequired); CurrentSchema.Id = GetTypeId(type, false); GenerateISerializableContract(type, (JsonISerializableContract)contract); break; #endif #if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE40) case JsonContractType.Dynamic: #endif case JsonContractType.Linq: CurrentSchema.Type = JsonSchemaType.Any; break; default: throw new JsonException("Unexpected contract type: {0}".FormatWith(CultureInfo.InvariantCulture, contract)); } } return(Pop().Schema); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Palestine); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Mauritius); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Barbados); }
/// <summary> /// Convert <see cref="Iran.EnumValues"/> to full region code likes 'BE-DE', 'BE-WAL'. /// </summary> /// <param name="values"></param> /// <returns></returns> public static string ToFullRegionCode(this EnumValues values) { return($"IR-{values.ToRegionCode()}"); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.StVAndG); }
/// <summary> /// Get CEP-1 / Cosmos Region Code. /// </summary> /// <param name="values"></param> /// <returns></returns> public static long ToNumericRegionCode(this EnumValues values) { return(values.GetAttr <EnumValues, RegionCodeAttribute>().CRCode); }
private JsonSchema GenerateInternal(Type type, bool valueRequired) { ValidationUtils.ArgumentNotNull(type, "type"); string resolvedId = GetTypeId(type, false); string explicitId = GetTypeId(type, true); if (!string.IsNullOrEmpty(resolvedId)) { JsonSchema resolvedSchema = _resolver.GetSchema(resolvedId); if (resolvedSchema != null) { return(resolvedSchema); } } // test for unresolved circular reference if (_stack.Any(tc => tc.Type == type)) { throw new Exception("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".FormatWith(CultureInfo.InvariantCulture, type)); } Push(new TypeSchema(type, new JsonSchema())); if (explicitId != null) { CurrentSchema.Id = explicitId; } CurrentSchema.Title = GetTitle(type); CurrentSchema.Description = GetDescription(type); if (CollectionUtils.IsDictionaryType(type)) { // To-Do: include null CurrentSchema.Type = JsonSchemaType.Object; Type keyType; Type valueType; ReflectionUtils.GetDictionaryKeyValueTypes(type, out keyType, out valueType); if (keyType != null) { // can be converted to a string if (typeof(IConvertible).IsAssignableFrom(keyType)) { CurrentSchema.AdditionalProperties = GenerateInternal(valueType, false); } } } else if (CollectionUtils.IsCollectionType(type)) { // To-Do: include null CurrentSchema.Type = JsonSchemaType.Array; JsonArrayAttribute arrayAttribute = JsonTypeReflector.GetJsonContainerAttribute(type) as JsonArrayAttribute; bool allowNullItem = (arrayAttribute != null) ? arrayAttribute.AllowNullItems : false; Type collectionItemType = ReflectionUtils.GetCollectionItemType(type); if (collectionItemType != null) { CurrentSchema.Items = new List <JsonSchema>(); CurrentSchema.Items.Add(GenerateInternal(collectionItemType, !allowNullItem)); } } else { CurrentSchema.Type = GetJsonSchemaType(type, valueRequired); if (HasFlag(CurrentSchema.Type, JsonSchemaType.Object)) { CurrentSchema.Id = GetTypeId(type, false); JsonObjectContract contract = ContractResolver.ResolveContract(type) as JsonObjectContract; if (contract == null) { throw new Exception("Could not resolve contract for '{0}'.".FormatWith(CultureInfo.InvariantCulture, type)); } CurrentSchema.Properties = new Dictionary <string, JsonSchema>(); foreach (JsonProperty property in contract.Properties) { if (!property.Ignored) { Type propertyMemberType = ReflectionUtils.GetMemberUnderlyingType(property.Member); JsonSchema propertySchema = GenerateInternal(propertyMemberType, property.Required); if (property.DefaultValue != null) { propertySchema.Default = JToken.FromObject(property.DefaultValue); } CurrentSchema.Properties.Add(property.PropertyName, propertySchema); } } if (type.IsSealed) { CurrentSchema.AllowAdditionalProperties = false; } } else if (CurrentSchema.Type == JsonSchemaType.Integer && type.IsEnum && !type.IsDefined(typeof(FlagsAttribute), true)) { CurrentSchema.Enum = new List <JToken>(); CurrentSchema.Options = new Dictionary <JToken, string>(); EnumValues <ulong> enumValues = EnumUtils.GetNamesAndValues <ulong>(type); foreach (EnumValue <ulong> enumValue in enumValues) { JToken value = JToken.FromObject(enumValue.Value); CurrentSchema.Enum.Add(value); CurrentSchema.Options.Add(value, enumValue.Name); } } } return(Pop().Schema); }
/// <summary> /// Convert to <see cref="CountryCode"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static CountryCode ToCountryCode(this EnumValues value) { return(CountryCode.IR); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Austria); }
/// <summary> /// Get Cosmos Region Enum value / CEP-1 from the given enum values. /// </summary> /// <param name="value"></param> /// <returns></returns> public static RegionEnumValue GetRegionEnumValue(this EnumValues value) { return(RegionEnumValue.Of(() => value)); }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.TrinidadAndTobago); }
private void ExportObject(EnumValues.FilterType type, String filename) { if (psobj != null && psobj.Count() > 0) { Utility.ExportObject exobj = new Utility.ExportObject(); switch (type) { case EnumValues.FilterType.XML: exobj.XML(psobj, filename); break; case EnumValues.FilterType.CSV: exobj.CSV(psobj, filename); break; case EnumValues.FilterType.TXT: exobj.TXT(psobj, filename); break; } exobj = null; } }
/// <summary> /// Convert to <see cref="Country"/> /// </summary> /// <param name="value"></param> /// <returns></returns> public static Country ToCountry(this EnumValues value) { return(Country.Belarus); }