例如有⼀个类,名为:TransactionOrder
public class TransactionOrder{
public string TransactionOrderlID { get; set; } public System.Guid MemberID { get; set; }
public System.Guid TransactionTypeID { get; set; } public decimal PayCoin { get; set; }}
定义⼀个⽅法GetPropertyInfoArray:
/// /// 获取类下所有属性名称///
///
static PropertyInfo[] GetPropertyInfoArray(){
PropertyInfo[] props = null; try {
Type type = typeof(TransactionOrder);
object obj = Activator.CreateInstance(type);
props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); }
catch (Exception ex) {
Console.WriteLine(ex.Message); }
return props;}
调⽤⽅法:
var prop = GetPropertyInfoArray();foreach (var item in prop){
Console.WriteLine(item.Name + \"=o.\" + item.Name+\);}
因篇幅问题不能全部显示,请点此查看更多更全内容