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; }
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; }
public object InitializeFromDictionary(Type objectType, IDictionary<string, object> values) { ValueProvider dictionaryProvider = new DictionaryValueProvider(values); ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new InitializerModelBinderContext(dictionaryProvider); object obj = binder.Bind(objectType, context); return obj; }
public object InitializeFromDictionary(Type objectType, IDictionary <string, object> values) { ValueProvider dictionaryProvider = new DictionaryValueProvider(values); ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new InitializerModelBinderContext(dictionaryProvider); object obj = binder.Bind(objectType, context); return(obj); }
public void Setup() { _dictionary = new Dictionary <string, object> { { "StringValue", "Value" }, { "IntValue", "47" }, { "Created", "2010-03-01 12:34:56.123" }, { "Duration", "12:34:56.123" }, { "SubClass_Street", "123 American Way" }, { "SubClass_City", "Tulsa" }, { "SubClass_State", "OK" }, }; ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new TestModelBinderContext(_dictionary); object obj = binder.Bind(typeof(BinderTestClass), context); _result = obj as BinderTestClass; }
public void Setup() { _dictionary = new Dictionary<string, object> { {"StringValue", "Value"}, {"IntValue", "47"}, {"Created", "2010-03-01 12:34:56.123"}, {"Duration", "12:34:56.123"}, {"SubClass_Street", "123 American Way"}, {"SubClass_City", "Tulsa"}, {"SubClass_State", "OK"}, }; ModelBinder binder = new FastModelBinder(); ModelBinderContext context = new TestModelBinderContext(_dictionary); object obj = binder.Bind(typeof (BinderTestClass), context); _result = obj as BinderTestClass; }
T AskInner <T>(string question, params string[] options) { Console.WriteLine(question); bool unanswered = true; for (int i = 0; i < options.Length; i++) { Console.WriteLine("{0}. {1}", i, options[i]); } Console.Write("Answer:"); Silly <T> silly = null; do { try { string result = Console.ReadLine(); var dict = new Dictionary <string, object>() { { "answer", result } }; var fmd = new FastModelBinder(); var cxt = new AskContext(dict); silly = fmd.Bind <Silly <T> >(cxt); unanswered = false; } catch (Exception) { Console.WriteLine("Whoops. Looks like something went wrong."); } } while (unanswered); return(silly.answer); }