public PropertyTreeBinderImpl(IPropertyTreeBinderErrors errors,
                               PropertyTreeBinderOptions options)
 {
     _errors = errors;
     this.directiveFactory = new SerializerDirectiveFactory(this);
     _options = options;
 }
        public void ReadOnly_should_cause_properties_to_be_read_only()
        {
            var opts = new PropertyTreeBinderOptions();

            opts = PropertyTreeBinderOptions.ReadOnly(opts);

            Assert.Throws <InvalidOperationException>(
                () => opts.ExpressionContext = new ExpressionContext()
                );
        }
Пример #3
0
        public void Bind_should_apply_global_expression_context_and_local_expression_context()
        {
            var opts = new PropertyTreeBinderOptions {
                ExpressionContext = new ExpressionContext {
                    Data = { { "element", 30 } }
                }
            };

            const string text = @"<fileTarget u='${a + q + element}'> </fileTarget>";
            var          f    = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts);

            Assert.Equal(60, f.Properties.GetInt32("u"));
        }
Пример #4
0
        public void Bind_should_bind_expression_string()
        {
            PropertyTreeReader pt = LoadContent("beta-upsilon.xml");

            Assert.True(pt.Read());

            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["text"] = "Text from expr";
            Beta b = pt.Bind(new Beta(), opts);

            Assert.Equal("Text from expr", b.D);
        }
Пример #5
0
        public void Bind_should_bind_expression_value_via_string_conversion()
        {
            PropertyTreeReader pt = LoadContent("beta-upsilon-3.xml");

            Assert.True(pt.Read());

            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["host"] = "carbonfrost.com";
            Beta b = pt.Bind(new Beta(), opts);

            Assert.Equal(new Uri("https://carbonfrost.com/health"), b.C);
        }
Пример #6
0
        public void Bind_should_bind_expression_value()
        {
            PropertyTreeReader pt = LoadContent("beta-upsilon-2.xml");

            Assert.True(pt.Read());

            var obj  = new Alpha();
            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["obj"] = obj;
            Beta b = pt.Bind(new Beta(), opts);

            Assert.Equal(obj, b.A);
        }
Пример #7
0
        public void Bind_should_apply_to_add_operator()
        {
            PropertyTreeReader pt = LoadContent("omicron-upsilon.xml");

            Assert.True(pt.Read());

            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["team"] = new { url = new Uri("https://example.com") };

            var b = pt.Bind(new Omicron(), opts);

            Assert.Equal(new Uri("https://example.com"), b.B.C);
        }
Пример #8
0
        public void Bind_should_collect_expression_value_on_IPropertiesContainer()
        {
            PropertyTreeReader pt = LoadContent("beta-upsilon.xml");

            Assert.True(pt.Read());

            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["text"] = "Text from expr";

            var b = pt.Bind(new FakePropertiesContainer(), opts);

            // Assert.IsAssignableFrom<Expression>(b.Properties["d"]);
        }
Пример #9
0
        public void Bind_should_use_properties_for_expressions_even_for_reflection()
        {
            var opts = new PropertyTreeBinderOptions {
                ExpressionContext = new ExpressionContext {
                    Data = { { "element", 20 } }
                }
            };

            const string text = @"<fileTarget s='${element}'> </fileTarget>";
            var          f    = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts);

            Assert.Equal(0, f.S); // Shouldn't be available to reflection
            Assert.Equal(20, f.Properties.GetInt32("s"));
            Assert.IsInstanceOf <CallExpression>(f.Properties.GetProperty <Expression>("s"));
        }
Пример #10
0
        public void Bind_should_collect_multiple_expression_values_on_lists()
        {
            var doc = @"<delta b='${a} ${b}' />";
            PropertyTreeReader pt = PropertyTreeReader.CreateXml(StreamContext.FromText(doc));

            Assert.True(pt.Read());

            var opts = new PropertyTreeBinderOptions();

            opts.ExpressionContext.Data["a"] = new Beta();
            opts.ExpressionContext.Data["b"] = new Beta();

            var b = pt.Bind <Delta>(opts);

            Assert.Equal(2, b.B.Count);
        }
Пример #11
0
        public void Bind_should_apply_property_type_conversion()
        {
            var opts = new PropertyTreeBinderOptions {
                ExpressionContext = new ExpressionContext {
                    Data =
                    {
                        { "m", "https://"    },
                        { "b", "example.org" },
                    }
                }
            };

            const string text = @"<fileTarget u='${m}${b}/yas'> </fileTarget>";
            var          f    = PropertyTree.FromStreamContext(StreamContext.FromText(text)).Bind <F>(opts);

            Assert.Equal(new Uri("https://example.org/yas"), f.Properties.GetProperty <Uri>("u"));
        }
Пример #12
0
 public static PropertyTreeMetaObjectBinder Create(PropertyTreeBinderOptions options)
 {
     options = options ?? new PropertyTreeBinderOptions();
     return(new PropertyTreeBinderImpl(PropertyTreeBinderErrors.Default, options));
 }