Beispiel #1
0
        public override void SetValue(IDbDataParameter parameter, T value)
        {
            var result = ExtractAttributeEnum.GetEnumValue <T>(value);

            if (result != null)
            {
                if (string.IsNullOrEmpty(result))
                {
                    parameter.Value = DBNull.Value;
                }
                else
                {
                    parameter.Value = result;
                }
            }
            else
            {
                throw new EnumStringNotMappedException <T>();
            }
        }
Beispiel #2
0
        public override T Parse(object value)
        {
            string valueString = (string)value;

            if (_dictionary.TryGetValue(valueString, out T result))
            {
                return(result);
            }
            else
            {
                try
                {
                    result = (T)ExtractAttributeEnum.GetEnumFromValue <T>(value);
                    _dictionary.Add(valueString, result);
                    return(result);
                }
                catch (Exception)
                {
                    throw new EnumStringParseException <T>(value);
                }
            }
        }