Пример #1
0
        private static void Merge(object source, object target, Type type)
        {
            var browser = TypeBrowser.Create(type);

            foreach (TypeBrowser.ElementInfo element in browser.Attributes.Concat(browser.Elements))
            {
                object value = element.GetValue(source);
                if (element.IsCollection)
                {
                    foreach (object item in (IEnumerable)value)
                    {
                        MergeValue(element, target, item);
                    }
                }
                else
                {
                    MergeValue(element, target, value);
                }
            }

            if (source is IHtmlContent htmlContent && (htmlContent.Text != null))
            {
                ((IHtmlContent)target).Text = htmlContent.Text;
            }
        }
Пример #2
0
        public void TestElements()
        {
            TypeBrowser browser = TypeBrowser.Create(typeof(DerivedClass));

            // Check that the base was searched
            var property = browser.FindElement(new XmlComponent(null, "Base.Private", null));

            Assert.That(property.Name, Is.EqualTo("BPrivate"));
            property = browser.FindElement(new XmlComponent(null, "Base.Protected", null));
            Assert.That(property.Name, Is.EqualTo("BProtected"));

            // Check namespaces
            property = browser.FindElement(new XmlComponent(null, "Derived.Public", null));
            Assert.That(property.Name, Is.EqualTo("DPublic"));
            property = browser.FindElement(new XmlComponent(null, "Derived.Public", "ns"));
            Assert.That(property.Name, Is.EqualTo("DPublicNs"));

            // Check a readonly property
            property = browser.FindElement(new XmlComponent(null, "Derived.Private", null));
            Assert.That(property.Name, Is.EqualTo("DPrivate"));

            // Makes sure we don't have any attributes
            Assert.That(browser.FindElement(new XmlComponent(null, "Derived.Attribute", null)),
                        Is.Null);
            Assert.That(browser.FindElement(new XmlComponent(null, "Derived.Field", null)),
                        Is.Null);

            Assert.That(browser.Elements.Count(), Is.EqualTo(6));
        }
Пример #3
0
        public void TestAttributes()
        {
            TypeBrowser browser = TypeBrowser.Create(typeof(DerivedClass));

            // Make sure the namespaces work
            var property = browser.FindAttribute(new XmlComponent(null, "Derived.Attribute", null));

            Assert.That(property.Name, Is.EqualTo("DAttribute"));

            Assert.That(browser.FindAttribute(new XmlComponent(null, "Derived.Public", null)),
                        Is.Null); // This is an element
            Assert.That(browser.FindAttribute(new XmlComponent(null, "Derived.Field", null)),
                        Is.Null); // This isn't a property

            Assert.That(browser.Attributes.Count(), Is.EqualTo(1));

            // Make sure the cache works
            Assert.That(TypeBrowser.Create(typeof(DerivedClass)), Is.SameAs(browser));
            Assert.That(TypeBrowser.Create(typeof(BaseClass)), Is.Not.SameAs(browser));
        }
Пример #4
0
 public void SetUp()
 {
     this.browser = TypeBrowser.Create(typeof(DerivedClass));
 }