本文整理汇总了C#中INode.Select方法的典型用法代码示例。如果您正苦于以下问题:C# INode.Select方法的具体用法?C# INode.Select怎么用?C# INode.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INode
的用法示例。
在下文中一共展示了INode.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Assemble
static SelectOutput Assemble(INode[] roots, INode[][] result)
{
var n = new INode[result.Select(z => z.Length).Max()];
foreach (var t in result)
{
for (var j = 0; j < t.Length; j++)
{
if (t[j] != null)
{
n[j] = t[j];
}
}
}
return new SelectOutput(n, roots);
}
示例2: ProcessMember
private void ProcessMember(MemberInfo member, object info, IDocument doc, INode context)
{
// Process only members that have the XPath attribute attached.
XPathAttribute[] attrs = (XPathAttribute[]) member.GetCustomAttributes(typeof(XPathAttribute), true);
if (attrs.Length == 0) return;
ISelection results;
if (context == null)
results = doc.Select(attrs[0].path);
else
results = context.Select(attrs[0].path);
Type member_type;
if (member is PropertyInfo)
member_type = ((PropertyInfo)member).PropertyType;
else
member_type = ((FieldInfo)member).FieldType;
if (member_type.IsArray) {
// Create a new array of the type of the member.
// The size of the array is the size of the xpath results.
Type element_type = member_type.GetElementType();
object[] items = (object[]) Array.CreateInstance(element_type, results.Count);
ConstructorInfo constructor = element_type.GetConstructor(Type.EmptyTypes);
// For each of these new objects, descend into its members and fill them recursively
// by processing the attached xpath expressions. Note that these expressions are
// evaluated with xpath context placed at the xpath result for the parent object.
int i = 0;
while (results.MoveNext()) {
object item = constructor.Invoke(new object[0]);
Extract(item, doc, results.Current);
items[i++] = item;
}
// Assign the array of filled results to the actual array field in the parent
AssignMember(member, info, items);
} else {
if (results.Count == 0) {
Console.WriteLine ("Path {0} didn't produce any value for field {1}.",
attrs[0].path, member.Name);
return;
} else if (results.Count > 1) {
Console.WriteLine ("Path {0} produced {1} values for field {2}. Only first one used.",
attrs[0].path, results.Count, member.Name);
}
results.MoveNext(); // move to first result
switch (member_type.Name) {
case "Int32":
Int32 tval;
if (Int32.TryParse(results.Current.Value, out tval))
AssignMember(member, info, tval);
break;
case "String":
AssignMember(member, info, results.Current.Value);
break;
default:
object item;
item = RetrieveMember(member, info);
if (item == null) {
item = CreateMemberInstance(member);
if (item == null) {
Console.WriteLine("Skipping member {0} since it need to be created but it has no " +
"parameterless constructor.", member.Name);
return;
}
AssignMember(member, info, item);
}
Extract(item, doc, results.Current);
break;
}
}
}