예제 #1
0
        public void Setup()
        {
            _dictionary = new Dictionary<string, object>
                {
                    {"StringValue", "Value"},
                    {"IntValue", "47"},
                    {"Created", "2010-03-01 12:34:56.123"},
                    {"Updated", "2010-03-15 10:34:49.983"},
                    {"Duration", "12:34:56.123"},
                    {"SubClass.Street", "123 American Way"},
                    {"SubClass.City", "Tulsa"},
                    {"SubClass.State", "OK"},
                    //no enum value provided on purpose
                };

            ValueProvider dictionaryProvider = new DictionaryValueProvider(_dictionary);
            ValueProvider jsonProvider = new JsonValueProvider(@"{ Names: [""One"", ""Two"", ""Three""], SubClass: { ZipCode: ""90210"" }, SubClasses: [ { ZipCode: ""68106"" }, { ZipCode: ""68154"" } ] }");

            var providers = new MultipleValueProvider(new[] { dictionaryProvider, jsonProvider });

            ModelBinder binder = new FastModelBinder();
            ModelBinderContext context = new TestModelBinderContext(providers);

            object obj = binder.Bind(typeof(BinderTestClass), context);

            _result = obj as BinderTestClass;
        }
예제 #2
0
        static ValueProvider CreateDictionaryProvider(IEnumerable<ICommandLineElement> elements)
        {
            Dictionary<string, object> dictionary = elements.Where(x => x is IDefinitionElement)
                .Cast<IDefinitionElement>()
                .Select(x => new Tuple<string, object>(x.Key, x.Value))
                .Union(elements.Where(x => x is ISwitchElement)
                       	.Cast<ISwitchElement>()
                       	.Select(x => new Tuple<string, object>(x.Key, x.Value)))
                .ToDictionary(x => x.First, x => x.Second, StringComparer.InvariantCultureIgnoreCase);

            var provider = new DictionaryValueProvider(dictionary);

            return provider;
        }
예제 #3
0
        static ValueProvider CreateDictionaryProvider(IEnumerable <ICommandLineElement> elements)
        {
            Dictionary <string, object> dictionary = elements.Where(x => x is IDefinitionElement)
                                                     .Cast <IDefinitionElement>()
                                                     .Select(x => new Tuple <string, object>(x.Key, x.Value))
                                                     .Union(elements.Where(x => x is ISwitchElement)
                                                            .Cast <ISwitchElement>()
                                                            .Select(x => new Tuple <string, object>(x.Key, x.Value)))
                                                     .ToDictionary(x => x.First, x => x.Second, StringComparer.InvariantCultureIgnoreCase);

            var provider = new DictionaryValueProvider(dictionary);

            return(provider);
        }