控制台程序:
class Program
{
static void Main(string[] args)
{
User u = new User();
u.name = "ahbool";
u.gender = "男";
u.age = "1";
Console.WriteLine(GetProperties(u));
}
public static string GetProperties<T>(T t)
{
string tStr = string.Empty;
if (t == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return tStr;
}
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = i