コード例 #1
0
ファイル: Endpoint.cs プロジェクト: ChadBurggraf/small-fry
        public void SetParameterPatterns(object patternConstraints)
        {
            this.ParameterPatterns.Clear();

            IDictionary<string, object> dict = new Dictionary<string, object>();
            dict.AddDynamic(patternConstraints);

            foreach (KeyValuePair<string, object> pair in dict)
            {
                Regex regex = pair.Value as Regex;

                if (regex != null)
                {
                    this.ParameterPatterns[pair.Key] = regex;
                }
                else
                {
                    string value = pair.Value as string;

                    if (!string.IsNullOrEmpty(value))
                    {
                        this.ParameterPatterns[pair.Key] = new Regex(value, RegexOptions.Compiled);
                    }
                }
            }
        }
コード例 #2
0
        public void RouteValueBinderBindPrimitives()
        {
            RouteValueBinder binder = new RouteValueBinder();
            IDictionary<string, object> inputValues = new Dictionary<string, object>();
            IDictionary<string, Type> types = new Dictionary<string, Type>();

            inputValues.AddDynamic(new { id = "42", date = "2012-09-18T18:30:00Z" });
            types.AddDynamic(new { id = typeof(long), date = typeof(DateTime) });

            IDictionary<string, object> boundValues = binder.Bind(inputValues, types);
            Assert.IsNotNull(boundValues);
            Assert.AreEqual(42L, boundValues["id"]);
            Assert.AreEqual(new DateTime(2012, 9, 18, 18, 30, 0, DateTimeKind.Utc), boundValues["date"]);
        }
コード例 #3
0
        public void RouteValueBinderOverrideType()
        {
            RouteValueBinder binder = new RouteValueBinder();
            binder.AddParser(new NoOpRouteParameterParser(new Type[] { typeof(DateTime) }));
            IDictionary<string, object> inputValues = new Dictionary<string, object>();
            IDictionary<string, Type> types = new Dictionary<string, Type>();

            inputValues.AddDynamic(new { id = "42", date = "2012-09-18T18:30:00Z" });
            types.AddDynamic(new { id = typeof(long), date = typeof(DateTime) });

            // NoOpRouteParameterParser throws a NotImplementedException during parsing.
            // This should cause the binder to fail the bind on the DateTime constraint.
            IDictionary<string, object> boundValues = binder.Bind(inputValues, types);
            Assert.IsNull(boundValues);
        }