public static List <Type> FindSimilarTypes(List <Type> types, Type type) { ByNameAttribute dbClass = Attribute.GetCustomAttribute(type, typeof(ByNameAttribute)) as ByNameAttribute; if (dbClass != null) { return(FindSimilarTypes(types, dbClass.Name)); } else { return(FindSimilarTypes(types, type.Name)); } }
private PropertyInfo FindProperty(Type type, PropertyInfo property) { string propertyName = property.Name; ByNameAttribute byNameAttribute = Attribute.GetCustomAttribute(property, typeof(ByNameAttribute)) as ByNameAttribute; if (byNameAttribute != null) { propertyName = byNameAttribute.Name; } PropertyInfo propertyInfo = type.GetProperty(propertyName); if (propertyInfo != null) { return(propertyInfo); } propertyInfo = type.GetProperty(propertyName.ToLower());//全小写 if (propertyInfo != null) { return(propertyInfo); } string property2 = propertyName[0].ToString().ToUpper() + propertyName.Substring(1);//小写转大写 propertyInfo = type.GetProperty(property2); if (propertyInfo != null) { return(propertyInfo); } string property3 = propertyName[0].ToString().ToLower() + propertyName.Substring(1);//大写转小写 propertyInfo = type.GetProperty(property3); if (propertyInfo != null) { return(propertyInfo); } return(null); }