本文整理汇总了C#中IDomObject.Render方法的典型用法代码示例。如果您正苦于以下问题:C# IDomObject.Render方法的具体用法?C# IDomObject.Render怎么用?C# IDomObject.Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDomObject
的用法示例。
在下文中一共展示了IDomObject.Render方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareNodes
bool CompareNodes(IDomObject n, IDomObject compareToNode, string path)
{
var outerHtml = n.Render();
var compareToOuterHtml = (compareToNode == null) ? "" : compareToNode.Render();
var getAttributes = new Func<IDomObject, string>(f => (f.Attributes == null) ? "" : string.Join(",", f.Attributes.Select(a => a.Key + "=" + a.Value)));
var thisNodeEquals = (compareToNode != null
&& n.NodeName == compareToNode.NodeName
&& n.NodeType == compareToNode.NodeType
&& n.NodeValue == compareToNode.NodeValue)
&& getAttributes(n) == getAttributes(compareToNode);
var nodeHtmlEquals = (compareToNode != null && outerHtml == compareToOuterHtml);
var pathAttributes = "";
if (n.Attributes != null)
{
var nSelectorAttributes = n.Attributes.Where(a => a.Key == "id" || a.Key == "class");
if (nSelectorAttributes.Any())
{
var idAttribute = nSelectorAttributes.Where(sa => sa.Key == "id");
var classAttribute = nSelectorAttributes.Where(sa => sa.Key == "class");
if (idAttribute.Any()) pathAttributes = "#" + idAttribute.First().Value;
else
if (classAttribute.Any()) pathAttributes = "." + classAttribute.First().Value;
}
}
path = path + ">" + n.NodeName + pathAttributes + "(" + n.Index.ToString() + ")";
if (thisNodeEquals)
{
if (n.HasChildren && compareToNode != null)
{
return TraverseNode(n, compareToNode, path);
}
return true;
}
else
{
var p = n;
var pp = "";
var breakNow = false;
var diff = new Diff();
do
{
if (p != null && p.Attributes != null)
{
var idAttr = p.Attributes.Where(a => a.Key == "id");
if (idAttr.Any())
{
pp = p.NodeName + "#" + idAttr.First().Value + " " + pp;
breakNow = true;
}
}
var hasClassAttribute = false;
if (!breakNow)
{
if (p != null && p.Attributes != null)
{
var idCssClass = p.Attributes.Where(a => a.Key == "class");
if (idCssClass.Any())
{
hasClassAttribute = true;
pp = p.NodeName.ToLower() + "." + idCssClass.First().Value.Replace(" ", ".") + ((pp!="")?" > " + pp:"");
}
}
}
if (!breakNow && !hasClassAttribute)
{
if (p.NodeType == NodeType.TEXT_NODE)
diff.isText = true;
if (p.NodeType == NodeType.ELEMENT_NODE)
{
var indexSelector = "";
if (p.ParentNode.ChildNodes.Count(t=>t.NodeName==p.NodeName)> 1) indexSelector = ":nth-child(" + (p.Index+1).ToString() + ")";
pp = p.NodeName.ToLower() + indexSelector + ((pp != "") ? " > " + pp : ""); //(" + p.Index.ToString() + ")
}
}
p = p.ParentNode;
}
while (!(p == null || breakNow));
diff.selector = pp;
diff.compareSourceHtml = outerHtml;
diff.compareWithHtml = compareToOuterHtml;
Diffs.Add(diff);
return false;
//.........这里部分代码省略.........