Skip to content

Commit

Permalink
Merge pull request #87 from VeyronSakai/fix/inject-attribute
Browse files Browse the repository at this point in the history
Fix Extensions.IsInjectAttribute() logic
  • Loading branch information
VeyronSakai authored Apr 17, 2024
2 parents 6ae6a81 + eaa5495 commit 2d70dfd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion VContainerAnalyzer/Analyzers/FieldAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static void Analyze(SymbolAnalysisContext context)
return;
}

var attribute = fieldSymbol.GetAttributes().FirstOrDefault(x => x.AttributeClass.IsInjectAttribute());
var attribute = fieldSymbol.GetAttributes().FirstOrDefault(x => x.AttributeClass.IsVContainerInjectAttribute());
if (attribute == null)
{
return;
Expand Down
2 changes: 1 addition & 1 deletion VContainerAnalyzer/Analyzers/PropertyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static void Analyze(SymbolAnalysisContext context)
}

var attribute = propertySymbol.GetAttributes()
.FirstOrDefault(x => x.AttributeClass.IsInjectAttribute());
.FirstOrDefault(x => x.AttributeClass.IsVContainerInjectAttribute());
if (attribute == null)
{
return;
Expand Down
16 changes: 14 additions & 2 deletions VContainerAnalyzer/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ internal static bool IsPreserveAttribute(this ITypeSymbol attributeClass)
return baseType != null && IsPreserveAttribute(baseType);
}

internal static bool IsInjectAttribute(this ITypeSymbol attributeClass)
internal static bool IsVContainerInjectAttribute(this ITypeSymbol attributeClass)
{
var containingNamespace = attributeClass.ContainingNamespace;
if (containingNamespace is not { Name: "VContainer" })
{
return false;
}

containingNamespace = containingNamespace.ContainingNamespace;
if (containingNamespace is not { Name: "" })
{
return false;
}

if (attributeClass.Name == InjectAttributeName)
{
return true;
}

var baseType = attributeClass.BaseType;
return baseType != null && IsInjectAttribute(baseType);
return baseType != null && IsVContainerInjectAttribute(baseType);
}
}

0 comments on commit 2d70dfd

Please sign in to comment.