Get the type of the object[] array by reflection and the values of the fields and fields to which this type is

Source: Internet
Author: User

private string T_account (object[] list)
{
StringBuilder code = new StringBuilder ();
Get data type
Type t = list[0]. GetType ();
list<string> str = new list<string> ();
Get all fields of type
fieldinfo[] fields = T.getfields (BindingFlags.NonPublic | BindingFlags.Instance);
Code. Appendline ("<table class= ' mytable ' ><thead><tr>");
foreach (FieldInfo fi in fields)
{
Extract the post-compilation field name
Match m = Regex.match (FI. Name, @ "(?<=\<). + (?=\>)");
Code. Append ("<td>"). Append (M.value). Appendline ("</td>");
Str. ADD (M.value);
}
Code. Appendline ("</tr>");
for (int i=0;i<list. length;i++)
{
Object Ob=activator.createinstance (t);
Code. Appendline ("<tr>");
foreach (FieldInfo fi in fields)
{
Extract the post-compilation field name
Match m = Regex.match (FI. Name, @ "(?<=\<). + (?=\>)");
Get the value of the corresponding field of the class
Code. Append ("<td>"). Append (FI. GetValue (List[0])). Appendline ("</td>");
Str. ADD (M.value);
}
Code. Appendline ("</tr>");
}
Code. Appendline ("</table>");
string s = code. ToString ();
Return code. ToString ();
}

Get the type of the object[] array by reflection and the values of the fields and fields to which this type is

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.