using System;
using System.Reflection;
class RowAdapter
{
private string Name { get; set; }
public long Id { get; set; }
}
class Program
{
public static void Main(string[] args)
{
RowAdapter row = new RowAdapter();
Type type = typeof(RowAdapter);
//或者 Type type = row.GetType();
//设置公有属性
PropertyInfo pubproperty = type.GetProperty("Id");
pubproperty.SetValue(row, 1);
//设置私有属性
BindingFlags bindAttr = BindingFlags.Instance | BindingFlags.NonPublic
PropertyInfo priproperty = type.GetProperty("Name", bindAttr);
priproperty.SetValue(row, "hello world!");
}
}