本文整理汇总了C#中Scope.ToXmlString方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.ToXmlString方法的具体用法?C# Scope.ToXmlString怎么用?C# Scope.ToXmlString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.ToXmlString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}