Exemple #1
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);
            };
        }
Exemple #2
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);
            };
        }