예제 #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
        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;
        }
예제 #4
0
        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);
        }
예제 #5
0
        public void Bootstrap(RouteCollection routeCollection)
        {
            TraceLogProvider.Configure(LogLevel.Debug);

            ModelBinder modelBinder = new FastModelBinder();

            RouteBuilder routeBuilder = new ActorRouteBuilder("actors/", modelBinder, routeCollection.Add);

            var actor = new EchoActor(new ThreadPoolActionQueue());

            routeBuilder.BuildRoute(() => actor, x => x.EchoChannel);
        }
예제 #6
0
        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;
        }
예제 #7
0
		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;
		}
예제 #8
0
        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);
        }