当前位置: 首页>>代码示例>>C#>>正文


C# INode.Select方法代码示例

本文整理汇总了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);
 }
开发者ID:vadimostanin,项目名称:CA,代码行数:15,代码来源:ComplexSelector.cs

示例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;
            }
        }
    }
开发者ID:nerochiaro,项目名称:webcontent-cs,代码行数:77,代码来源:Extractor.cs


注:本文中的INode.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。