namespace ConsoleApplication1
{class Program
{static void Main(string[] args)
{#region 通过字符串设置实体类的值
//初始化一个实体类//Student model_stu = new Student();
//string id_str = "stu_id";
//string name_str = "stu_name";
//string addr_str = "stu_address";
//Type type = model_stu.GetType();//获取类型
//PropertyInfo property_info_id = type.GetProperty(id_str);
//PropertyInfo property_info_name = type.GetProperty(name_str);
//PropertyInfo property_info_addr = type.GetProperty(addr_str);
通过字符串获取实体类的值
Student model_stu =
{
stu_id
= = =};
id_str = name_str = addr_str =Type type
= model_stu.GetType();PropertyInfo property_info_id =
PropertyInfo property_info_name
=PropertyInfo property_info_addr
=Console.WriteLine(property_info_id.GetValue(model_stu));
Console.WriteLine(property_info_name.GetValue(model_stu));
Console.WriteLine(property_info_addr.GetValue(model_stu));
Console.ReadKey();
}
}
{
stu_id { ; stu_name { ; stu_address { ;}
}