/// <summary> /// 获取父类信息 /// </summary> /// <param name="ctype"></param> /// <returns></returns> public static ClrType GetBaseClass(ClrType ctype, out string typeName) { InheritanceTypeRefMoveableCollection col = ctype.InheritanceTypeRefs; typeName = "System.Object"; if (col != null && col.Count > 0) { typeName = col[0].Name; ClrType baseType = col[0].ClrType; return(baseType); } return(null); }
/// <summary> /// 填充基类的传入泛型参数 /// </summary> private static void FillBaseTypeGenericArgs(ClrType ctype, List <string> lstArgs) { if (EntityConfig.IsSystemType(ctype)) { return; } InheritanceTypeRefMoveableCollection col = ctype.InheritanceTypeRefs; if (col != null && col.Count > 0) { string args = col[0].TypeArguments; if (!string.IsNullOrEmpty(args)) { GetBaseTypeGenericArgs(args, lstArgs); } } }
/// <summary> /// 判断是否存在成员 /// </summary> /// <returns></returns> public static bool ExistsMember <T>(ClrType type, string menberName, bool checkBase) where T : Member { bool hasName = false; //检查基类 if (checkBase) { InheritanceTypeRefMoveableCollection col = type.InheritanceTypeRefs; if (col != null && col.Count > 0) { string baseType = col[0].TypeTypeName; bool isBaseType = IsSystemTypeName(baseType); if (!isBaseType) { ClrType btype = col[0].ClrType; if (btype != null) { hasName = ExistsMember <T>(btype, menberName); } } } } if (hasName) { return(hasName); } //检查本类 foreach (object pro in type.Members) { T cPro = pro as T; if (cPro != null) { if (cPro.Name == menberName) { return(true); } } } return(false); }
/// <summary> /// 获取该类的所有成员 /// </summary> /// <typeparam name="T">成员类型</typeparam> /// <param name="lst">集合</param> /// <param name="type">类型</param> /// <param name="fillBase">是否级联父类</param> public static void FillAllMember <T>(List <T> lst, Dictionary <string, bool> dicExistsPropertyName, ClrType type, bool fillBase) where T : Member { if (fillBase) { InheritanceTypeRefMoveableCollection col = type.InheritanceTypeRefs; if (col != null && col.Count > 0) { string baseType = col[0].TypeTypeName; bool isBaseType = IsSystemTypeName(baseType); if (!isBaseType) { ClrType btype = col[0].ClrType; if (btype != null) { FillAllMember <T>(lst, dicExistsPropertyName, btype, fillBase); } } } } foreach (object pro in type.Members) { T cPro = pro as T; if (cPro != null && !dicExistsPropertyName.ContainsKey(cPro.Name) && !cPro.IsStatic) { dicExistsPropertyName[cPro.Name] = true; lst.Add(cPro); } } }