C# model转Dto 使用泛型即可实现
C# model转Dto 使用泛型即可实现 using System ; using System . Collections . Generic ; using System . Linq ; using System . Reflection ; using System . Text ; using System . Threading . Tasks ; namespace GlobalAPI { public class PropertyHelper { /// <summary> /// 反射得到实体类的字段名称和值 /// var dict = GetProperties(model); /// </summary> /// <typeparam name="T">实体类</typeparam> /// <param name="t">实例化</param> /// <returns></returns> public static Dictionary < object , object > GetProperties < T > ( T t ) { var ret = new Dictionary < object , object > ( ) ; if ( t == null ) { return null ; } PropertyInfo [ ]