Esempio n. 1
0
        public string GetVo4()
        {
            var expando = new ExpandoModel();

            expando.AddPropertyFilter(ExpandoPropertyFilterFactory.CreateExcludeFilter("bad"));
            expando.Set("A", () => Task.FromResult("abc"));
            expando.Set("B", async() => await Task.FromResult("abc"));
            expando.Set("bad", () => Task.FromResult("bad"));
            return(JsonConvert.SerializeObject(expando, Formatting.Indented));
        }
Esempio n. 2
0
        public string GetVo3()
        {
            var expando = new ExpandoModel();

            expando.AddPropertyFilter(ExpandoPropertyFilterFactory.CreateExcludeFilter("bad"));

            dynamic dynamicVo = expando;

            dynamicVo.a    = "222";
            dynamicVo.bad  = "bad";
            dynamicVo.good = "good";
            return(JsonConvert.SerializeObject(expando, Formatting.Indented));
        }
Esempio n. 3
0
        public void ExpandoToObjectTest()
        {
            // Set standard properties
            var expando = new ExpandoModel
            {
                ["Email"]    = "rick @west-wind.com",
                ["Password"] = "******",
                ["Name"]     = "Rickochet",
                ["Active"]   = true
            };

            var user = expando.ToObject <User>();

            Assert.Equal("rick @west-wind.com", user.Email);
            Assert.Equal("nonya123", user.Password);
            Assert.Equal("Rickochet", user.Name);
            Assert.True(user.Active);
        }
Esempio n. 4
0
        public void TestNestedExpandoTemplate_Issue350()
        {
            var model = new ExpandoModel()
            {
                IntProperty    = 23,
                StringProperty = "from string property",
                Properties     = new ExpandoObject()
            };
            var dictionary = (IDictionary <string, object>)model.Properties;

            dictionary.Add("Key1", "ExpandoObject Key1 value");

            Template.RegisterSafeType(typeof(ExpandoModel), new[] { "IntProperty", "StringProperty", "Properties" });
            const string templateString = @"Int: '{{IntProperty}}'; String: '{{StringProperty}}'; Expando: '{{Properties.Key1}}'";
            var          template       = Template.Parse(templateString);

            Assert.AreEqual(expected: "Int: '23'; String: 'from string property'; Expando: 'ExpandoObject Key1 value'",
                            actual: template.Render(Hash.FromAnonymousObject(model)));
        }