当前位置: 首页>>代码示例>>C#>>正文


C# Scope.Element方法代码示例

本文整理汇总了C#中Scope.Element方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.Element方法的具体用法?C# Scope.Element怎么用?C# Scope.Element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scope的用法示例。


在下文中一共展示了Scope.Element方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestContainer

		public void TestContainer(Format format, string expectedOutput)
		{
			var schema = new Scope();

			schema.Element<Item>()
				.Attributes()
				.Add(x => x.Name)
				.End()
				.Init();

			schema.Element<Container>()
				.Elements()
				.Add(x => x.Items)
				.End()
				.Init();

			var container = new Container(new[] {new Item("a"), new Item("b")});
			var output = schema.ToString(container, format);
			Assert.AreEqual(expectedOutput, output);
			
			var container2 = schema.Parse<Container>(output, format);
			Assert.AreEqual(container.Items.Count, container2.Items.Count);
			Assert.AreEqual(container.Items[0].Name, container2.Items[0].Name);
			Assert.AreEqual(container.Items[1].Name, container2.Items[1].Name);
		}
开发者ID:sergeyt,项目名称:xserializer,代码行数:25,代码来源:ImmutableObjectsTests.cs

示例2: Test

        public void Test()
        {
            var scope = new Scope();
            scope.Element<Custom>(new CustomSurrogate());

            scope.Element<Item>()
                .Elements()
                .Add(x => x.Name)
                .Add(x => x.Custom)
                .Add(x => x.Value)
                .End();

            var obj = new Item
            {
                Name = "item",
                Value = "test",
                Custom = new Custom
                {
                    InnerXml = "<test></test>"
                }
            };

            var xml = scope.ToXmlString(obj);

            var obj2 = new Item();
            scope.ReadXmlString(xml, obj2);

            Assert.AreEqual(obj.Name, obj2.Name);
            Assert.AreEqual(obj.Value, obj2.Value);
            Assert.AreEqual(obj.Custom.InnerXml, obj2.Custom.InnerXml);
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:31,代码来源:XmlSurrogateTests.cs

示例3: Rdl

        static Rdl()
        {
            var schema = new Scope(Ns.Rdl2005)
                .Type(s => Length.Parse(s), x => x.IsValid ? x.ToString() : "")
                .Type(s => ExpressionInfo.Parse(s), x => x.ToString())
                .Enum(DataElementOutput.Auto);

            var rdl = new[] {Ns.Rdl2005, Ns.Rdl2003, Ns.Rdl2008, Ns.Rdl2010};

            schema.Element<Report>()
                .Attributes()
                .Add(x => x.Name)
                .End()
                .Elements(rdl)
                .Add(x => x.Width)
                .Add(x => x.Body)
                .End()
                .Use(rdl);

            schema.Element<Body>()
                .Elements(rdl)
                .Add(x => x.Height)
                .Add(x => x.ReportItems)
                .End()
                .Use(rdl);

            var item = schema.Element<ReportItem>()
                .Attributes()
                .Add(x => x.Name)
                .End()
                .Elements(rdl)
                .Add(x => x.DataElementName)
                .Add(x => x.DataElementOutput)
                .End();

            item.Sub<TextBox>()
                .Elements(rdl)
                .Add(x => x.Value)
                .End()
                .Use(rdl);

            item.Sub<Rectangle>()
                .Elements(rdl)
                .Add(x => x.ReportItems)
                .End()
                .Use(rdl);

            Schema = schema;
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:49,代码来源:Rdl.cs

示例4: Test

        public void Test()
        {
            var schema = new Scope();

            var entity = schema.Element<Entity>()
                .Elements()
                .Add(x => x.Name)
                .Add(x => x.Element)
                .End();

            entity.Element<Element>()
                .Elements()
                .Add(x => x.Text)
                .End();

            var obj1 = new Entity
            {
                Name = "test",
                Element = new Element {Text = "hi"}
            };

            var xml = schema.ToXmlString(obj1);

            var obj2 = new Entity();
            schema.ReadXmlString(xml, obj2);

            Assert.AreEqual(obj1.Name, obj2.Name);
            Assert.AreEqual(obj1.Element.Text, obj2.Element.Text);
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:29,代码来源:SubScopeTest.cs

示例5: SkipUnknownElement

        public string SkipUnknownElement(string xml)
        {
            var scope = new Scope();
            scope.Element<Entity>()
                .Elements()
                .Add(x => x.Value)
                .End();

            var obj = new Entity();
            scope.ReadXmlString(xml, obj);
            return obj.Value;
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:12,代码来源:MiscTests.cs

示例6: MultipleNamespaces

        public string MultipleNamespaces(string xml)
        {
            var scope = new Scope("A", "B");
            scope.Element<Entity>()
                .Elements()
                .Add(x => x.Value)
                .End();

            var obj = new Entity();
            scope.ReadXmlString(xml, obj);
            return obj.Value;
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:12,代码来源:MiscTests.cs

示例7: Simple

		public void Simple(Format format, byte[] data, string expectedSerial)
		{
			var schema = new Scope();
			schema.Element<Item>()
				.Elements().Add(x => x.Data);

			var item = new Item {Data = data};
			var serial = schema.ToString(item, format);
			Assert.AreEqual(expectedSerial, serial);

			var item2 = schema.Parse<Item>(serial, format);
			Assert.NotNull(item2);
			Assert.AreEqual(item.Data, item2.Data);
		}
开发者ID:sergeyt,项目名称:xserializer,代码行数:14,代码来源:BlobTests.cs

示例8: MultiplePropertyNames

        public string MultiplePropertyNames(string xml)
        {
            var ns1 = XNamespace.Get("A");
            var ns2 = XNamespace.Get("B");

            var scope = new Scope();
            scope.Element<Entity>()
                .Elements()
                .Add(x => x.Value, ns1 + "Value", ns2 + "Value", ns1 + "Text", ns2 + "Text")
                .End();

            var obj = new Entity();
            scope.ReadXmlString(xml, obj);
            return obj.Value;
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:15,代码来源:MiscTests.cs

示例9: JustAttr

		public void JustAttr(Format format, string expectedOutput)
		{
			var schema = new Scope();

			schema.Element<Item>()
				.Attributes()
				.Add(x => x.Name)
				.End()
				.Init();

			var item1 = new Item("test");
			var output = schema.ToString(item1, format);
			Assert.AreEqual(expectedOutput, output);
			
			var item2 = schema.Parse<Item>(output, format);
			Assert.AreEqual(item1.Name, item2.Name);
		}
开发者ID:sergeyt,项目名称:xserializer,代码行数:17,代码来源:ImmutableObjectsTests.cs

示例10: DefaultValueAttribute

        public string DefaultValueAttribute(bool asAttr)
        {
            var schema = new Scope();
            var def = schema.Element<Entity>();

            if (asAttr)
            {
                def.Attributes().Add(x => x.StringProperty);
            }
            else
            {
                def.Elements().Add(x => x.StringProperty);
            }

            var entity = new Entity
            {
                StringProperty = "test"
            };

            return schema.ToXmlString(entity);
        }
开发者ID:sergeyt,项目名称:xserializer,代码行数:21,代码来源:DefaultValueTests.cs


注:本文中的Scope.Element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。