diff options
Diffstat (limited to 'src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs')
-rw-r--r-- | src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs new file mode 100644 index 000000000..efe00031b --- /dev/null +++ b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Text; +using Microsoft.CodeAnalysis; + +namespace ILLink.RoslynAnalyzer +{ + public static class RequiresISymbolExtensions + { + // TODO: Consider sharing with linker IsMethodInRequiresUnreferencedCodeScope method + public static bool IsInRequiresScope (this ISymbol member, string requiresAttribute) + { + if (member is ISymbol containingSymbol) { + if (containingSymbol.HasAttribute (requiresAttribute) + || (containingSymbol is not ITypeSymbol && + containingSymbol.ContainingType.HasAttribute (requiresAttribute))) { + return true; + } + } + if (member is IMethodSymbol { AssociatedSymbol: { } associated } && associated.HasAttribute (requiresAttribute)) + return true; + + return false; + } + } +} |