예제 #1
0
        //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);
            };
        }
예제 #2
0
        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);
            };
        }
예제 #3
0
 public static string Name(this GeoCountry value)
 {
     return(XEnum <GeoCountry> .Name((int)value));
 }
예제 #4
0
 public static string Name(this USCanadaState value)
 {
     return(XEnum <USCanadaState> .Name((int)value));
 }
예제 #5
0
 public static string Name(this BsKind val)
 => val == BsKind.None ? null : XEnum <BsKind> .Name((int)val).ToLower();