private bool TryParseSingleEnum <EnumType>(KeyValuePair <string, StringValues> Item, out EnumType EnumValue) where EnumType : Enum { if (!IsParameterValueEmpty(Item)) { CheckSingleParameterForMoreThanOne(Item); string Value = Item.Value[Item.Value.Count - 1]; string ValueLower = StringSupport.ToLowerFast(Value); var Dic = StringToEnumMap <EnumType> .GetDictionary(); if (Dic.ContainsKey(ValueLower)) { EnumValue = Dic[ValueLower]; return(true); } else { this.InvalidParameterList.Add(new InvalidSearchQueryParameter(Item.Key, Value, $"Unable to parse the provided value to an allowed value.")); } } #pragma warning disable CS8653 // A default expression introduces a null value for a type parameter. EnumValue = default; #pragma warning restore CS8653 // A default expression introduces a null value for a type parameter. return(false); }
public virtual void ParseModifier(string parameterName, IResourceTypeSupport IResourceTypeSupport, IKnownResource IKnownResource) { if (parameterName.Contains(FhirSearchQuery.TermSearchModifierDelimiter)) { string parameterNameModifierPart = parameterName.Split(FhirSearchQuery.TermSearchModifierDelimiter)[1]; var SearchModifierTypeDic = StringToEnumMap <Common.Enums.SearchModifierCode> .GetDictionary(); string ValueCaseCorrectly = StringSupport.ToLowerFast(parameterNameModifierPart); if (SearchModifierTypeDic.ContainsKey(ValueCaseCorrectly)) { this.Modifier = SearchModifierTypeDic[ValueCaseCorrectly]; } else { string TypedResourceName = parameterNameModifierPart; if (parameterNameModifierPart.Contains(".")) { char[] delimiters = { '.' }; TypedResourceName = parameterNameModifierPart.Split(delimiters)[0].Trim(); } if (IKnownResource.IsKnownResource(this.FhirVersionId, TypedResourceName)) { Common.Enums.ResourceType?ResourceType = IResourceTypeSupport.GetTypeFromName(TypedResourceName); if (ResourceType != null) { this.TypeModifierResource = ResourceType.Value; this.Modifier = SearchModifierCode.Type; } else { throw new ApplicationException($"Found a known resource to the FHIR API yet this resource was not found in the Enum list for {typeof(Common.Enums.ResourceType).Name}"); } } else { this.InvalidMessage = $"Unable to parse the given search parameter's Modifier: {parameterName}, "; this.IsValid = false; } } } else { this.Modifier = null; this.TypeModifierResource = null; } if (this.Modifier.HasValue) { SearchModifierCode[] oSupportedModifierArray = SearchQuerySupport.GetModifiersForSearchType(this.SearchParamTypeId); if (!oSupportedModifierArray.Any(x => x == this.Modifier.Value)) { this.InvalidMessage += $"The parameter's modifier: '{this.Modifier.GetCode()}' is not supported by this server for this search parameter type '{this.SearchParamTypeId.GetCode()}', the whole parameter was : '{this.RawValue}', "; this.IsValid = false; } } }
public static SearchComparator?GetPrefix(string value) { if (value.Length > 2) { //Are the first two char Alpha characters if (Regex.IsMatch(value.Substring(0, 2), @"^[a-zA-Z]+$")) { var SearchPrefixTypeDictionary = StringToEnumMap <SearchComparator> .GetDictionary(); if (SearchPrefixTypeDictionary.ContainsKey(value.Substring(0, 2))) { return(SearchPrefixTypeDictionary[value.Substring(0, 2)]); } } } return(null); }