private static void callGenericTypeMethod(IPropertyMapper map, PropertyInfo property) { var enumStringOfPropertyType = typeof(EnumStringType <>).MakeGenericType(property.PropertyType); var method = map.GetType().GetMethods().First(x => x.Name == "Type" && !x.GetParameters().Any()); var genericMethod = method.MakeGenericMethod(new[] { enumStringOfPropertyType }); genericMethod.Invoke(map, null); }
/// <summary> /// 将对象属性转换为字典 /// </summary> /// <param name="proMapper">The object.</param> /// <returns>Dictionary<System.String, System.Object>.</returns> public static Dictionary <string, object> ToDictionary(this IPropertyMapper proMapper) { if (proMapper == null) { return(null); } var dic = new Dictionary <string, object>(); var properties = proMapper.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var property in properties) { var propertyName = proMapper.MapPropertyName(property.Name); if (string.IsNullOrEmpty(propertyName)) { continue; } dic[propertyName] = property.GetValue(proMapper); } return(dic); }