本文整理汇总了C#中XElement.Attribute方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Attribute方法的具体用法?C# XElement.Attribute怎么用?C# XElement.Attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XElement
的用法示例。
在下文中一共展示了XElement.Attribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunInValidTests
/// <summary>
/// Runs test for InValid cases
/// </summary>
/// <param name="nodeType">XElement/XAttribute</param>
/// <param name="name">name to be tested</param>
public void RunInValidTests(string nodeType, string name)
{
XDocument xDocument = new XDocument();
XElement element = null;
try
{
switch (nodeType)
{
case "XElement":
element = new XElement(name, name);
xDocument.Add(element);
IEnumerable<XNode> nodeList = xDocument.Nodes();
break;
case "XAttribute":
element = new XElement(name, name);
XAttribute attribute = new XAttribute(name, name);
element.Add(attribute);
xDocument.Add(element);
XAttribute x = element.Attribute(name);
break;
case "XName":
XName xName = XName.Get(name, name);
break;
default:
break;
}
}
catch (XmlException)
{
return;
}
catch (ArgumentException)
{
return;
}
Assert.True(false, "Expected exception not thrown");
}
示例2: RunValidTests
/// <summary>
/// Runs test for valid cases
/// </summary>
/// <param name="nodeType">XElement/XAttribute</param>
/// <param name="name">name to be tested</param>
public void RunValidTests(string nodeType, string name)
{
XDocument xDocument = new XDocument();
XElement element = null;
switch (nodeType)
{
case "XElement":
element = new XElement(name, name);
xDocument.Add(element);
IEnumerable<XNode> nodeList = xDocument.Nodes();
Assert.True(nodeList.Count() == 1, "Failed to create element { " + name + " }");
xDocument.RemoveNodes();
break;
case "XAttribute":
element = new XElement(name, name);
XAttribute attribute = new XAttribute(name, name);
element.Add(attribute);
xDocument.Add(element);
XAttribute x = element.Attribute(name);
Assert.Equal(name, x.Name.LocalName);
xDocument.RemoveNodes();
break;
case "XName":
XName xName = XName.Get(name, name);
Assert.Equal(name, xName.LocalName);
Assert.Equal(name, xName.NamespaceName);
Assert.Equal(name, xName.Namespace.NamespaceName);
break;
default:
break;
}
}