public static T AsEnum <T>(this NameValueMap nameValueMap, string index) { if (nameValueMap.TryGetValueAs(index, out T enumValue)) { return(enumValue); } throw new InvalidValueTypeException("Value cannot be used as an enum"); }
public static bool AsBool(this NameValueMap nameValueMap, string index) { if (nameValueMap.TryGetValueAs(index, out bool boolValue)) { return(boolValue); } throw new InvalidValueTypeException("Value cannot be used as a boolean"); }
public static double AsDouble(this NameValueMap nameValueMap, string index) { if (nameValueMap.TryGetValueAs(index, out double doubleValue)) { return(doubleValue); } throw new InvalidValueTypeException("Value cannot be used as a double"); }
public static int AsInt(this NameValueMap nameValueMap, string index) { if (nameValueMap.TryGetValueAs(index, out int intValue)) { return(intValue); } throw new InvalidValueTypeException("Value cannot be used as an integer"); }
public static string AsString(this NameValueMap nameValueMap, string index) { if (nameValueMap.TryGetValueAs(index, out string strValue)) { return(strValue); } throw new InvalidValueTypeException("Value cannot be used as a string"); }
public static IEnumerable <T> GetValueAsCollection <T>(this NameValueMap nameValueMap, string index) { if (!nameValueMap.TryGetValueAs(index, out string outString)) { throw new InvalidValueTypeException("Value cannot be used as a collection because it is not a string"); } return(outString .Split(Separators, StringSplitOptions.RemoveEmptyEntries) .Select(item => { if (!dataConverter.TryGetValueFromObjectAs(item, out T outValue)) { throw new InvalidValueTypeException("Value cannot be used as a collection"); } return outValue; }) .ToList()); }