Example #1
0
        public ISearchParameter CreateParameter(string value)
        {
            if (ValuePattern != null && !ValuePattern.IsMatch(value))
            {
                return(new WrongSearchParameter(Identifier, value, string.Format("value does not match regular expression '{0}'", ValuePattern.ToString())));
            }
            T tvalue;

            try
            {
                tvalue = (T)Convert.ChangeType(value, Type.GetTypeCode(typeof(T)));
            }
            catch (FormatException) {
                return(new WrongSearchParameter(Identifier, value, string.Format("value cannot be parsed as '{0}'", Type.GetTypeCode(typeof(T)))));
            }

            if (ValueRange != null && !ValueRange.ContainsValue(tvalue))
            {
                return(new WrongSearchParameter(Identifier, value, string.Format("value in not within range '{0}'", ValueRange)));
            }

            return(new TypedParameter <T>(Identifier, tvalue));
        }