Пример #1
0
        public ValueProviderResult GetValue(string key)
        {
            ConditionalGeneratorSimple <Region> generatorR = new ConditionalGeneratorSimple <Region>(_values);

            generatorR.SetKeyValueExpression <string>("nameR", (r, n) => r.RegionName.StartsWith(n, StringComparison.OrdinalIgnoreCase));

            ConditionalGeneratorSimple <City> generatorC = new ConditionalGeneratorSimple <City>(_values);

            generatorC.SetKeyValueExpression <string>("nameC", (r, n) => r.CityName.StartsWith(n, StringComparison.OrdinalIgnoreCase));

            Func <Region, bool> expressionR = generatorR.GetConditional().Compile();
            Func <City, bool>   expressionC = generatorC.GetConditional().Compile();

            return(new ValueProviderResult(new MulticastDelegate[] { expressionR, expressionC }, key, CultureInfo.CurrentCulture));
        }
Пример #2
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            try
            {
                var values = actionContext.Request.RequestUri.ParseQueryString();

                var generatorR = new ConditionalGeneratorSimple <Region>(values);
                generatorR.SetKeyValueExpression <string>("nameR", (r, n) => r.RegionName.StartsWith(n, StringComparison.OrdinalIgnoreCase));

                var generatorC = new ConditionalGeneratorSimple <City>(values);
                generatorC.SetKeyValueExpression <string>("nameC", (r, n) => r.CityName.StartsWith(n, StringComparison.OrdinalIgnoreCase));

                bindingContext.Model = new MulticastDelegate[] { generatorR.GetConditional().Compile(),
                                                                     generatorC.GetConditional().Compile() };

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }