Search

just show me the code

Tuesday, September 29, 2009

Xml Literals in vb

Here I am creating an XElement in C#

   19         public static XElement PropertyTable(List<Property> propertyList)
   20         {
   21             XElement root = new XElement("div");
   22             root.Add(new XElement("div"
   23                 , new XAttribute("class", "propertyCount hand")
   24                 , string.Format("{0} properties", propertyList.Count)));
   25             XElement tableElement = new XElement("table", new XAttribute("class", "propertyTable"));
   26             root.Add(tableElement);
   27             XElement headerRow = new XElement("tr");
   28             headerRow.Add(new XElement("th", "Code"));
   29             headerRow.Add(new XElement("th", "Value"));
   30             tableElement.Add(headerRow);
   32
   33             foreach (Property p in propertyList)
   34             {
   35                 XElement projectRow = new XElement("tr");
   36                 projectRow.Add(new XElement("td", p.Code));
   37                 projectRow.Add(new XElement("td", p.Value));
   38                 tableElement.Add(projectRow);
   39             }
   40             return root;
   41         }

Here I am creating the EXACT SAME XElement in VB using xml literals


   19     Public Function PropertyTable(ByVal propertyList As List(Of [Property])) As XElement
   20       Dim root = <div>
   21                    <div class="propertyCount hand"><%= String.Format("{0} properties", propertyList.Count) %></div>
   22                    <table class="propertyTable">
   23                      <tr>
   24                        <th>Code</th>
   25                        <th>Value</th>
   26                      </tr>
   27                      <%= From p In propertyList Select _
   28                        <tr>
   29                          <td><%= p.Code %></td>
   30                          <td><%= p.Value %></td>
   31                        </tr> %>
   32                    </table>
   33                  </div>
   34       Return root
   35     End Function  

which would you rather read?  

No comments:

Post a Comment

Contributors