예제 #1
0
 public List<Member> GetMembers(CsvConverter csvReader)
 {
     List<Member> members = new List<Member>();
     var keys = csvReader.GetKeys();
     while (true)
     {
         List<string> values = csvReader.GetValues();
         if (values == null) break;
         Member member = new Member();
         Type memberType = typeof(Member);
         for (int i = 0; i < keys.Count; i++)
         {
             var key = keys[i].Replace(" ", "");
             var property = memberType.GetProperty(key);
             if (property != null)
             {
                 property.SetValue(member, values[i], null);
             }
         }
         members.Add(member);
     }
     return members;
 }
예제 #2
0
 private List<Member> ParseFilterTable(Response response)
 {
     var document = new HtmlDocument();
     document.LoadHtml(response.Content);
     var table = document.DocumentNode.SelectSingleNode("//table[@class='filter_tab_table']");
     var headers = table.SelectNodes("//input[@class='filterlink']").Select(elem => elem.GetAttributeValue("value", null)).ToList();
     var dataRows = table.SelectNodes("//tr[starts-with(@class, 'table_tr_color')]");
     List<Member> members = new List<Member>();
     var memberType = typeof(Member);
     foreach (var tr in dataRows)
     {
         var dataFields = tr.SelectNodes("./td[starts-with(@class, 'listtxt_tab')]");
         var index = 0;
         var member = new Member();
         foreach (var td in dataFields)
         {
             var key = headers[index++];
             var link = td.SelectSingleNode("./a");
             string value = null;
             if (link == null)
             {
                 value = td.InnerText;
             }
             else
             {
                 var href = link.GetAttributeValue("href", null);
                 var linkProp = memberType.GetProperty(key + "Link");
                 if (linkProp != null)
                 {
                     var url = ResolveUrl(href);
                     linkProp.SetValue(member, url, null);
                 }
                 value = link.InnerText;
             }
             var prop = memberType.GetProperty(key);
             if (prop != null)
             {
                 prop.SetValue(member, value, null);
             }
         }
         members.Add(member);
     }
     return members;
 }