本文整理汇总了C#中DomNode.GetLocalAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# DomNode.GetLocalAttribute方法的具体用法?C# DomNode.GetLocalAttribute怎么用?C# DomNode.GetLocalAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNode
的用法示例。
在下文中一共展示了DomNode.GetLocalAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSetAttribute
public void TestSetAttribute()
{
DomNodeType type = new DomNodeType("child");
AttributeInfo info = GetIntAttribute("int");
type.Define(info);
DomNode test = new DomNode(type);
Assert.False(test.IsAttributeSet(info));
test.SetAttribute(info, 2);
Assert.AreEqual(test.GetAttribute(info), 2);
Assert.AreEqual(test.GetLocalAttribute(info), 2);
Assert.True(test.IsAttributeSet(info));
test.SetAttribute(info, null);
Assert.True(test.IsAttributeDefault(info));
Assert.Null(test.GetLocalAttribute(info));
Assert.False(test.IsAttributeSet(info));
}
示例2: Equals
private bool Equals(DomNode n1, DomNode n2)
{
if (n1 == null || n2 == null)
return n1 == n2;
if (n1.Type != n2.Type)
return false;
if (n1.ChildInfo != n2.ChildInfo)
return false;
foreach (AttributeInfo info in n1.Type.Attributes)
{
object val1 = n1.GetLocalAttribute(info);
object val2 = n2.GetLocalAttribute(info);
if (val1 == null || val2 == null)
if (val1 != val2)
return false;
}
foreach (ChildInfo info in n1.Type.Children)
{
if (info.IsList)
{
IList<DomNode> children1 = n1.GetChildList(info);
IList<DomNode> children2 = n1.GetChildList(info);
if (children1.Count != children2.Count)
return false;
for (int i = 0; i < children1.Count; i++)
if (!Equals(children1[i], children2[i]))
return false;
}
else
{
DomNode child1 = n1.GetChild(info);
DomNode child2 = n2.GetChild(info);
if (!Equals(child1, child2))
return false;
}
}
return true;
}
示例3: Serialize
private static void Serialize(DomNode node, Dictionary<DomNode, int> nodeIds, BinaryWriter writer)
{
writer.Write(node.Type.Name);
foreach (AttributeInfo info in node.Type.Attributes)
{
object value = node.GetLocalAttribute(info);
// references are serialized as an integer id
if (info.Type.Type == AttributeTypes.Reference)
{
DomNode reference = value as DomNode;
int refId;
if (reference == null ||
!nodeIds.TryGetValue(reference, out refId))
{
// null, or reference was external to top level nodes and their subtrees
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(refId);
}
}
else
{
if (value == null)
{
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(info.Type.Convert(value));
}
}
}
foreach (ChildInfo info in node.Type.Children)
{
if (info.IsList)
{
IList<DomNode> children = node.GetChildList(info);
writer.Write(children.Count);
foreach (DomNode child in children)
Serialize(child, nodeIds, writer);
}
else
{
DomNode child = node.GetChild(info);
if (child == null)
{
writer.Write(false);
}
else
{
writer.Write(true);
Serialize(child, nodeIds, writer);
}
}
}
}