|
|
@@ -83,9 +83,9 @@ namespace ET.Analyzer
|
|
|
/// <summary>
|
|
|
/// INamedTypeSymbol 是否有指定的Attribute
|
|
|
/// </summary>
|
|
|
- public static bool HasAttribute(this INamedTypeSymbol namedTypeSymbol, string AttributeName)
|
|
|
+ public static bool HasAttribute(this ITypeSymbol typeSymbol, string AttributeName)
|
|
|
{
|
|
|
- foreach (AttributeData? attributeData in namedTypeSymbol.GetAttributes())
|
|
|
+ foreach (AttributeData? attributeData in typeSymbol.GetAttributes())
|
|
|
{
|
|
|
if (attributeData.AttributeClass?.ToString() == AttributeName)
|
|
|
{
|
|
|
@@ -96,6 +96,33 @@ namespace ET.Analyzer
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public static bool HasAttributeInTypeAndBaseTyes(this ITypeSymbol typeSymbol, string AttributeName)
|
|
|
+ {
|
|
|
+ if (typeSymbol.HasAttribute(AttributeName))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var baseType in typeSymbol.BaseTypes())
|
|
|
+ {
|
|
|
+ if (baseType.HasAttribute(AttributeName))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IEnumerable<ITypeSymbol> BaseTypes(this ITypeSymbol typeSymbol)
|
|
|
+ {
|
|
|
+ ITypeSymbol? baseType = typeSymbol.BaseType;
|
|
|
+ while (baseType!=null)
|
|
|
+ {
|
|
|
+ yield return baseType;
|
|
|
+ baseType = baseType.BaseType;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// INamedTypeSymbol 是否有指定的基类Attribute
|
|
|
/// </summary>
|
|
|
@@ -536,5 +563,35 @@ namespace ET.Analyzer
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 类型symbol是否是实体类 包含 enity及其子类 lsentity及其子类
|
|
|
+ /// </summary>
|
|
|
+ public static bool IsETEntity(this ITypeSymbol typeSymbol)
|
|
|
+ {
|
|
|
+ string typeName = typeSymbol.ToString();
|
|
|
+ string? baseType = typeSymbol.BaseType?.ToString();
|
|
|
+ return typeName == Definition.EntityType || baseType == Definition.EntityType || baseType == Definition.LSEntityType;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 类型symbol是否是EntiyRef 或EntityWeakRef类
|
|
|
+ /// </summary>
|
|
|
+ public static bool IsEntityRefOrEntityWeakRef(this ITypeSymbol typeSymbol)
|
|
|
+ {
|
|
|
+ if (typeSymbol is not INamedTypeSymbol namedTypeSymbol)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!namedTypeSymbol.IsGenericType)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ string typeName = namedTypeSymbol.Name;
|
|
|
+ return typeName is Definition.EntityRefType or Definition.EntityWeakRefType;
|
|
|
+ }
|
|
|
}
|
|
|
}
|