//Func<T, int> toInt; //public StringXEnumConverter() : this(null) { } //public StringXEnumConverter(Func<T, int> toInt = null) //{ // if(toInt == null) //throw new ArgumentNullException(); // toInt = t => t.GetHashCode(); // this.toInt = toInt; //} public StringXEnumConverter() { base.Serialize = (t) => { string val = XEnum <T> .Name(t); return(val); }; base.Deserialize = (str) => { if (XEnum <T> .TryGetValueIgnoreCase(str, out T val)) { return(val); } throw new ArgumentOutOfRangeException($"Dictionary key {str}"); //T val = XEnum<T>.ValueIgnoreCase(str); }; }
public StringXEnumConverterCamelCase() { Serialize = t => { string val = XEnum <T> .Name(t).ToCamelCaseFromCodePascalCase(); return(val); }; Deserialize = str => { if (XEnum <T> .TryGetValueIgnoreCase(str, out T val)) { return(val); } throw new ArgumentOutOfRangeException($"Dictionary key {str}"); //T val = XEnum<T>.ValueIgnoreCase(str); }; }
public static string Name(this GeoCountry value) { return(XEnum <GeoCountry> .Name((int)value)); }
public static string Name(this USCanadaState value) { return(XEnum <USCanadaState> .Name((int)value)); }
public static string Name(this BsKind val) => val == BsKind.None ? null : XEnum <BsKind> .Name((int)val).ToLower();