1820 lines
63 KiB
C#
1820 lines
63 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal static class SymbolExtensions
|
|
{
|
|
private static readonly Func<TypeSymbol, Symbol, bool, bool> s_hasInvalidTypeParameterFunc = (TypeSymbol type, Symbol containingSymbol, bool unused) => HasInvalidTypeParameter(type, containingSymbol);
|
|
|
|
internal static bool HasParamsParameter(this Symbol member)
|
|
{
|
|
ImmutableArray<ParameterSymbol> parameters = member.GetParameters();
|
|
if (!parameters.IsEmpty)
|
|
{
|
|
return parameters.Last().IsParams;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static ImmutableArray<ParameterSymbol> GetParameters(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).Parameters;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
return ((MethodSymbol)member).Parameters;
|
|
}
|
|
return ImmutableArray<ParameterSymbol>.Empty;
|
|
}
|
|
|
|
internal static ImmutableArray<TypeWithAnnotations> GetParameterTypes(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).ParameterTypesWithAnnotations;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
return ((MethodSymbol)member).ParameterTypesWithAnnotations;
|
|
}
|
|
return ImmutableArray<TypeWithAnnotations>.Empty;
|
|
}
|
|
|
|
internal static bool GetIsVararg(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind == 9)
|
|
{
|
|
return ((MethodSymbol)member).IsVararg;
|
|
}
|
|
if ((int)kind != 15)
|
|
{
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static ImmutableArray<RefKind> GetParameterRefKinds(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).ParameterRefKinds;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
return ((MethodSymbol)member).ParameterRefKinds;
|
|
}
|
|
return default(ImmutableArray<RefKind>);
|
|
}
|
|
|
|
internal static int GetParameterCount(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Invalid comparison between Unknown and I4
|
|
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0010: Invalid comparison between Unknown and I4
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0015: Invalid comparison between Unknown and I4
|
|
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if (kind - 5 > 1)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).ParameterCount;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
return ((MethodSymbol)member).ParameterCount;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
internal static bool HasParameterContainingPointerType(this Symbol member)
|
|
{
|
|
ImmutableArray<TypeWithAnnotations>.Enumerator enumerator = member.GetParameterTypes().GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
if (enumerator.Current.Type.ContainsPointer())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsEventOrPropertyWithImplementableNonPublicAccessor(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
PropertySymbol propertySymbol = (PropertySymbol)symbol;
|
|
if (!isImplementableAndNotPublic(propertySymbol.GetMethod))
|
|
{
|
|
return isImplementableAndNotPublic(propertySymbol.SetMethod);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
EventSymbol eventSymbol = (EventSymbol)symbol;
|
|
if (!isImplementableAndNotPublic(eventSymbol.AddMethod))
|
|
{
|
|
return isImplementableAndNotPublic(eventSymbol.RemoveMethod);
|
|
}
|
|
return true;
|
|
static bool isImplementableAndNotPublic(MethodSymbol accessor)
|
|
{
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000f: Invalid comparison between Unknown and I4
|
|
if (accessor.IsImplementable())
|
|
{
|
|
return (int)accessor.DeclaredAccessibility != 6;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool IsImplementable(this MethodSymbol methodOpt)
|
|
{
|
|
if ((object)methodOpt != null && !methodOpt.IsSealed)
|
|
{
|
|
if (!methodOpt.IsAbstract)
|
|
{
|
|
return methodOpt.IsVirtual;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsAccessor(this MethodSymbol methodSymbol)
|
|
{
|
|
return (object)methodSymbol.AssociatedSymbol != null;
|
|
}
|
|
|
|
public static bool IsAccessor(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind == 9)
|
|
{
|
|
return ((MethodSymbol)symbol).IsAccessor();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsIndexedPropertyAccessor(this MethodSymbol methodSymbol)
|
|
{
|
|
return methodSymbol.AssociatedSymbol?.IsIndexedProperty() ?? false;
|
|
}
|
|
|
|
public static bool IsOperator(this MethodSymbol methodSymbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Invalid comparison between Unknown and I4
|
|
if ((int)methodSymbol.MethodKind != 9)
|
|
{
|
|
return (int)methodSymbol.MethodKind == 2;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static bool IsOperator(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind == 9)
|
|
{
|
|
return ((MethodSymbol)symbol).IsOperator();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsIndexer(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind == 15)
|
|
{
|
|
return ((PropertySymbol)symbol).IsIndexer;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsIndexedProperty(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind == 15)
|
|
{
|
|
return ((PropertySymbol)symbol).IsIndexedProperty;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsUserDefinedConversion(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0016: Invalid comparison between Unknown and I4
|
|
if ((int)symbol.Kind == 9)
|
|
{
|
|
return (int)((MethodSymbol)symbol).MethodKind == 2;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static int CustomModifierCount(this MethodSymbol method)
|
|
{
|
|
int num = 0;
|
|
TypeWithAnnotations returnTypeWithAnnotations = method.ReturnTypeWithAnnotations;
|
|
num += returnTypeWithAnnotations.CustomModifiers.Length + method.RefCustomModifiers.Length;
|
|
num += returnTypeWithAnnotations.Type.CustomModifierCount();
|
|
ImmutableArray<ParameterSymbol>.Enumerator enumerator = method.Parameters.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
ParameterSymbol current = enumerator.Current;
|
|
TypeWithAnnotations typeWithAnnotations = current.TypeWithAnnotations;
|
|
num += typeWithAnnotations.CustomModifiers.Length + current.RefCustomModifiers.Length;
|
|
num += typeWithAnnotations.Type.CustomModifierCount();
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public static int CustomModifierCount(this Symbol m)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0023: Expected I4, but got Unknown
|
|
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0050: Expected I4, but got Unknown
|
|
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0053: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = m.Kind;
|
|
switch (kind - 1)
|
|
{
|
|
default:
|
|
switch (kind - 9)
|
|
{
|
|
default:
|
|
if ((int)kind != 20)
|
|
{
|
|
goto end_IL_000a;
|
|
}
|
|
break;
|
|
case 2:
|
|
case 5:
|
|
case 8:
|
|
break;
|
|
case 0:
|
|
return ((MethodSymbol)m).CustomModifierCount();
|
|
case 6:
|
|
return ((PropertySymbol)m).CustomModifierCount();
|
|
case 1:
|
|
case 3:
|
|
case 4:
|
|
case 7:
|
|
goto end_IL_000a;
|
|
}
|
|
goto case 0;
|
|
case 0:
|
|
case 3:
|
|
return ((TypeSymbol)m).CustomModifierCount();
|
|
case 4:
|
|
return ((EventSymbol)m).CustomModifierCount();
|
|
case 1:
|
|
case 2:
|
|
break;
|
|
end_IL_000a:
|
|
break;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)m.Kind);
|
|
}
|
|
|
|
public static int CustomModifierCount(this EventSymbol e)
|
|
{
|
|
return e.Type.CustomModifierCount();
|
|
}
|
|
|
|
public static int CustomModifierCount(this PropertySymbol property)
|
|
{
|
|
int num = 0;
|
|
TypeWithAnnotations typeWithAnnotations = property.TypeWithAnnotations;
|
|
num += typeWithAnnotations.CustomModifiers.Length + property.RefCustomModifiers.Length;
|
|
num += typeWithAnnotations.Type.CustomModifierCount();
|
|
ImmutableArray<ParameterSymbol>.Enumerator enumerator = property.Parameters.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
ParameterSymbol current = enumerator.Current;
|
|
TypeWithAnnotations typeWithAnnotations2 = current.TypeWithAnnotations;
|
|
num += typeWithAnnotations2.CustomModifiers.Length + current.RefCustomModifiers.Length;
|
|
num += typeWithAnnotations2.Type.CustomModifierCount();
|
|
}
|
|
return num;
|
|
}
|
|
|
|
internal static Symbol SymbolAsMember(this Symbol s, NamedTypeSymbol newOwner)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002b: Expected I4, but got Unknown
|
|
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002e: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = s.Kind;
|
|
switch (kind - 5)
|
|
{
|
|
default:
|
|
if ((int)kind != 15)
|
|
{
|
|
break;
|
|
}
|
|
return ((PropertySymbol)s).AsMember(newOwner);
|
|
case 1:
|
|
return ((FieldSymbol)s).AsMember(newOwner);
|
|
case 4:
|
|
return ((MethodSymbol)s).AsMember(newOwner);
|
|
case 6:
|
|
return ((NamedTypeSymbol)s).AsMember(newOwner);
|
|
case 0:
|
|
return ((EventSymbol)s).AsMember(newOwner);
|
|
case 2:
|
|
case 3:
|
|
case 5:
|
|
break;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)s.Kind);
|
|
}
|
|
|
|
internal static int GetMemberArity(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind != 4)
|
|
{
|
|
if ((int)kind == 9)
|
|
{
|
|
return ((MethodSymbol)symbol).Arity;
|
|
}
|
|
if ((int)kind != 11)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return ((NamedTypeSymbol)symbol).Arity;
|
|
}
|
|
|
|
internal static NamespaceOrTypeSymbol OfMinimalArity(this IEnumerable<NamespaceOrTypeSymbol> symbols)
|
|
{
|
|
NamespaceOrTypeSymbol result = null;
|
|
int num = int.MaxValue;
|
|
foreach (NamespaceOrTypeSymbol symbol in symbols)
|
|
{
|
|
int memberArity = symbol.GetMemberArity();
|
|
if (memberArity < num)
|
|
{
|
|
num = memberArity;
|
|
result = symbol;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
internal static ImmutableArray<TypeParameterSymbol> GetMemberTypeParameters(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002f: Expected I4, but got Unknown
|
|
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0032: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
switch (kind - 4)
|
|
{
|
|
default:
|
|
if ((int)kind != 15)
|
|
{
|
|
break;
|
|
}
|
|
goto case 1;
|
|
case 5:
|
|
return ((MethodSymbol)symbol).TypeParameters;
|
|
case 0:
|
|
case 7:
|
|
return ((NamedTypeSymbol)symbol).TypeParameters;
|
|
case 1:
|
|
case 2:
|
|
return ImmutableArray<TypeParameterSymbol>.Empty;
|
|
case 3:
|
|
case 4:
|
|
case 6:
|
|
break;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)symbol.Kind);
|
|
}
|
|
|
|
internal static ImmutableArray<TypeSymbol> GetMemberTypeArgumentsNoUseSiteDiagnostics(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002f: Expected I4, but got Unknown
|
|
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0032: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
switch (kind - 4)
|
|
{
|
|
default:
|
|
if ((int)kind != 15)
|
|
{
|
|
break;
|
|
}
|
|
goto case 1;
|
|
case 5:
|
|
return ImmutableArrayExtensions.SelectAsArray<TypeWithAnnotations, TypeSymbol>(((MethodSymbol)symbol).TypeArgumentsWithAnnotations, TypeMap.AsTypeSymbol);
|
|
case 0:
|
|
case 7:
|
|
return ImmutableArrayExtensions.SelectAsArray<TypeWithAnnotations, TypeSymbol>(((NamedTypeSymbol)symbol).TypeArgumentsWithAnnotationsNoUseSiteDiagnostics, TypeMap.AsTypeSymbol);
|
|
case 1:
|
|
case 2:
|
|
return ImmutableArray<TypeSymbol>.Empty;
|
|
case 3:
|
|
case 4:
|
|
case 6:
|
|
break;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)symbol.Kind);
|
|
}
|
|
|
|
internal static bool IsConstructor(this MethodSymbol method)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
MethodKind methodKind = method.MethodKind;
|
|
if ((int)methodKind == 1 || (int)methodKind == 14)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static bool HasThisConstructorInitializer(this MethodSymbol method, out ConstructorInitializerSyntax initializerSyntax)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Invalid comparison between Unknown and I4
|
|
if ((object)method != null && (int)method.MethodKind == 1 && method is SourceMemberMethodSymbol { SyntaxNode: ConstructorDeclarationSyntax syntaxNode } && syntaxNode.Initializer?.Kind() == SyntaxKind.ThisConstructorInitializer)
|
|
{
|
|
initializerSyntax = syntaxNode.Initializer;
|
|
return true;
|
|
}
|
|
initializerSyntax = null;
|
|
return false;
|
|
}
|
|
|
|
internal static bool IncludeFieldInitializersInBody(this MethodSymbol methodSymbol)
|
|
{
|
|
if (methodSymbol.IsConstructor() && (!methodSymbol.HasThisConstructorInitializer(out var initializerSyntax) || methodSymbol.ContainingType.IsDefaultValueTypeConstructor(initializerSyntax)) && !(methodSymbol is SynthesizedRecordCopyCtor))
|
|
{
|
|
return !Binder.IsUserDefinedRecordCopyConstructor(methodSymbol);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static bool IsDefaultValueTypeConstructor(this NamedTypeSymbol type, ConstructorInitializerSyntax initializerSyntax)
|
|
{
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
if (initializerSyntax.ArgumentList.Arguments.Count > 0 || !type.IsValueType)
|
|
{
|
|
return false;
|
|
}
|
|
bool flag = false;
|
|
bool result = false;
|
|
ImmutableArray<MethodSymbol>.Enumerator enumerator = type.InstanceConstructors.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
MethodSymbol current = enumerator.Current;
|
|
if (current.ParameterCount == 0)
|
|
{
|
|
if (flag)
|
|
{
|
|
return false;
|
|
}
|
|
flag = true;
|
|
result = current.IsDefaultValueTypeConstructor();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
internal static bool IsParameterlessConstructor(this MethodSymbol method)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Invalid comparison between Unknown and I4
|
|
if ((int)method.MethodKind == 1)
|
|
{
|
|
return method.ParameterCount == 0;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static bool IsDefaultValueTypeConstructor(this MethodSymbol method)
|
|
{
|
|
if (method.IsImplicitlyDeclared)
|
|
{
|
|
NamedTypeSymbol containingType = method.ContainingType;
|
|
if ((object)containingType != null && containingType.IsValueType)
|
|
{
|
|
return method.IsParameterlessConstructor();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static bool ShouldEmit(this MethodSymbol method)
|
|
{
|
|
if (method.IsDefaultValueTypeConstructor())
|
|
{
|
|
return false;
|
|
}
|
|
if (method is SynthesizedStaticConstructor synthesizedStaticConstructor && !synthesizedStaticConstructor.ShouldEmit())
|
|
{
|
|
return false;
|
|
}
|
|
if (method.IsPartialMethod() && (object)method.PartialImplementationPart == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
internal static MethodSymbol GetOwnOrInheritedAddMethod(this EventSymbol @event)
|
|
{
|
|
while ((object)@event != null)
|
|
{
|
|
MethodSymbol addMethod = @event.AddMethod;
|
|
if ((object)addMethod != null)
|
|
{
|
|
return addMethod;
|
|
}
|
|
@event = (@event.IsOverride ? @event.OverriddenEvent : null);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal static MethodSymbol GetOwnOrInheritedRemoveMethod(this EventSymbol @event)
|
|
{
|
|
while ((object)@event != null)
|
|
{
|
|
MethodSymbol removeMethod = @event.RemoveMethod;
|
|
if ((object)removeMethod != null)
|
|
{
|
|
return removeMethod;
|
|
}
|
|
@event = (@event.IsOverride ? @event.OverriddenEvent : null);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal static bool IsExplicitInterfaceImplementation(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).IsExplicitInterfaceImplementation;
|
|
}
|
|
return false;
|
|
}
|
|
return ((MethodSymbol)member).IsExplicitInterfaceImplementation;
|
|
}
|
|
return ((EventSymbol)member).IsExplicitInterfaceImplementation;
|
|
}
|
|
|
|
internal static bool IsPartialMethod(this Symbol member)
|
|
{
|
|
return (member as SourceMemberMethodSymbol)?.IsPartial ?? false;
|
|
}
|
|
|
|
internal static bool IsPartialImplementation(this Symbol member)
|
|
{
|
|
return (member as SourceOrdinaryMethodSymbol)?.IsPartialImplementation ?? false;
|
|
}
|
|
|
|
internal static bool IsPartialDefinition(this Symbol member)
|
|
{
|
|
return (member as SourceOrdinaryMethodSymbol)?.IsPartialDefinition ?? false;
|
|
}
|
|
|
|
internal static bool ContainsTupleNames(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).Type.ContainsTupleNames();
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
MethodSymbol methodSymbol = (MethodSymbol)member;
|
|
if (!methodSymbol.ReturnType.ContainsTupleNames())
|
|
{
|
|
return methodSymbol.Parameters.Any((ParameterSymbol p) => p.Type.ContainsTupleNames());
|
|
}
|
|
return true;
|
|
}
|
|
return ((EventSymbol)member).Type.ContainsTupleNames();
|
|
}
|
|
|
|
internal static ImmutableArray<Symbol> GetExplicitInterfaceImplementations(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ImmutableArrayExtensions.Cast<PropertySymbol, Symbol>(((PropertySymbol)member).ExplicitInterfaceImplementations);
|
|
}
|
|
return ImmutableArray<Symbol>.Empty;
|
|
}
|
|
return ImmutableArrayExtensions.Cast<MethodSymbol, Symbol>(((MethodSymbol)member).ExplicitInterfaceImplementations);
|
|
}
|
|
return ImmutableArrayExtensions.Cast<EventSymbol, Symbol>(((EventSymbol)member).ExplicitInterfaceImplementations);
|
|
}
|
|
|
|
internal static Symbol GetOverriddenMember(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).OverriddenProperty;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)member.Kind);
|
|
}
|
|
return ((MethodSymbol)member).OverriddenMethod;
|
|
}
|
|
return ((EventSymbol)member).OverriddenEvent;
|
|
}
|
|
|
|
internal static Symbol GetLeastOverriddenMember(this Symbol member, NamedTypeSymbol accessingTypeOpt)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)member).GetLeastOverriddenProperty(accessingTypeOpt);
|
|
}
|
|
return member;
|
|
}
|
|
return ((MethodSymbol)member).GetConstructedLeastOverriddenMethod(accessingTypeOpt, requireSameReturnType: false);
|
|
}
|
|
return ((EventSymbol)member).GetLeastOverriddenEvent(accessingTypeOpt);
|
|
}
|
|
|
|
internal static bool IsFieldOrFieldLikeEvent(this Symbol member, out FieldSymbol field)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000d: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = member.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind == 6)
|
|
{
|
|
field = (FieldSymbol)member;
|
|
return true;
|
|
}
|
|
field = null;
|
|
return false;
|
|
}
|
|
field = ((EventSymbol)member).AssociatedField;
|
|
return (object)field != null;
|
|
}
|
|
|
|
internal static string GetMemberCallerName(this Symbol member)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
if ((int)member.Kind == 9)
|
|
{
|
|
member = ((MethodSymbol)member).AssociatedSymbol ?? member;
|
|
}
|
|
if (!member.IsIndexer())
|
|
{
|
|
if (!member.IsExplicitInterfaceImplementation())
|
|
{
|
|
return member.Name;
|
|
}
|
|
return ExplicitInterfaceHelpers.GetMemberNameWithoutInterfaceName(member.Name);
|
|
}
|
|
return member.MetadataName;
|
|
}
|
|
|
|
public static bool IsCompilationOutputWinMdObj(this Symbol symbol)
|
|
{
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0016: Invalid comparison between Unknown and I4
|
|
CSharpCompilation declaringCompilation = symbol.DeclaringCompilation;
|
|
if (declaringCompilation != null)
|
|
{
|
|
return (int)((CompilationOptions)declaringCompilation.Options).OutputKind == 4;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static NamedTypeSymbol ConstructIfGeneric(this NamedTypeSymbol type, ImmutableArray<TypeWithAnnotations> typeArguments)
|
|
{
|
|
if (!type.TypeParameters.IsEmpty)
|
|
{
|
|
return type.Construct(typeArguments, unbound: false);
|
|
}
|
|
return type;
|
|
}
|
|
|
|
public static bool IsNestedType([NotNullWhen(true)] this Symbol? symbol)
|
|
{
|
|
if (symbol is NamedTypeSymbol)
|
|
{
|
|
return (object)symbol.ContainingType != null;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsAccessibleViaInheritance(this NamedTypeSymbol superType, NamedTypeSymbol subType, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
|
|
{
|
|
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: Invalid comparison between Unknown and I4
|
|
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0067: Invalid comparison between Unknown and I4
|
|
NamedTypeSymbol originalDefinition = superType.OriginalDefinition;
|
|
NamedTypeSymbol namedTypeSymbol = subType;
|
|
while ((object)namedTypeSymbol != null)
|
|
{
|
|
if ((object)namedTypeSymbol.OriginalDefinition == originalDefinition)
|
|
{
|
|
return true;
|
|
}
|
|
namedTypeSymbol = namedTypeSymbol.BaseTypeWithDefinitionUseSiteDiagnostics(ref useSiteInfo);
|
|
}
|
|
if (originalDefinition.IsInterface)
|
|
{
|
|
ImmutableArray<NamedTypeSymbol>.Enumerator enumerator = subType.AllInterfacesWithDefinitionUseSiteDiagnostics(ref useSiteInfo).GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
if ((object)enumerator.Current.OriginalDefinition == originalDefinition)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
if ((int)superType.TypeKind == 12)
|
|
{
|
|
return (int)subType.TypeKind == 12;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsNoMoreVisibleThan(this Symbol symbol, TypeSymbol type, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
|
|
{
|
|
return type.IsAtLeastAsVisibleAs(symbol, ref useSiteInfo);
|
|
}
|
|
|
|
public static bool IsNoMoreVisibleThan(this Symbol symbol, TypeWithAnnotations type, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
|
|
{
|
|
return type.IsAtLeastAsVisibleAs(symbol, ref useSiteInfo);
|
|
}
|
|
|
|
internal static void AddUseSiteInfo(this Symbol? symbol, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo, bool addDiagnostics = true)
|
|
{
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((object)symbol != null && useSiteInfo.AccumulatesDiagnostics)
|
|
{
|
|
UseSiteInfo<AssemblySymbol> useSiteInfo2 = symbol.GetUseSiteInfo();
|
|
if (addDiagnostics)
|
|
{
|
|
useSiteInfo.AddDiagnostics(useSiteInfo2);
|
|
}
|
|
useSiteInfo.AddDependencies(useSiteInfo2);
|
|
}
|
|
}
|
|
|
|
public static LocalizableErrorArgument GetKindText(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
return symbol.Kind.Localize();
|
|
}
|
|
|
|
internal static NamespaceOrTypeSymbol? ContainingNamespaceOrType(this Symbol symbol)
|
|
{
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Invalid comparison between Unknown and I4
|
|
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001a: Invalid comparison between Unknown and I4
|
|
Symbol containingSymbol = symbol.ContainingSymbol;
|
|
if ((object)containingSymbol != null)
|
|
{
|
|
SymbolKind kind = containingSymbol.Kind;
|
|
if ((int)kind == 4 || kind - 11 <= 1)
|
|
{
|
|
return (NamespaceOrTypeSymbol)containingSymbol;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal static Symbol? ContainingNonLambdaMember(this Symbol? containingMember)
|
|
{
|
|
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002e: Invalid comparison between Unknown and I4
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0019: Invalid comparison between Unknown and I4
|
|
while ((object)containingMember != null && (int)containingMember.Kind == 9)
|
|
{
|
|
MethodSymbol methodSymbol = (MethodSymbol)containingMember;
|
|
if ((int)methodSymbol.MethodKind != 0 && (int)methodSymbol.MethodKind != 17)
|
|
{
|
|
break;
|
|
}
|
|
containingMember = containingMember.ContainingSymbol;
|
|
}
|
|
return containingMember;
|
|
}
|
|
|
|
internal static ParameterSymbol? EnclosingThisSymbol(this Symbol containingMember)
|
|
{
|
|
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Invalid comparison between Unknown and I4
|
|
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0010: Invalid comparison between Unknown and I4
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0015: Invalid comparison between Unknown and I4
|
|
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0030: Invalid comparison between Unknown and I4
|
|
Symbol symbol = containingMember;
|
|
NamedTypeSymbol namedTypeSymbol;
|
|
while (true)
|
|
{
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind != 6)
|
|
{
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 11)
|
|
{
|
|
namedTypeSymbol = (NamedTypeSymbol)symbol;
|
|
break;
|
|
}
|
|
return null;
|
|
}
|
|
MethodSymbol methodSymbol = (MethodSymbol)symbol;
|
|
if ((int)methodSymbol.MethodKind == 0 || (int)methodSymbol.MethodKind == 17)
|
|
{
|
|
symbol = methodSymbol.ContainingSymbol;
|
|
continue;
|
|
}
|
|
return methodSymbol.ThisParameter;
|
|
}
|
|
namedTypeSymbol = symbol.ContainingType;
|
|
break;
|
|
}
|
|
if (!namedTypeSymbol.IsScriptClass)
|
|
{
|
|
return null;
|
|
}
|
|
return namedTypeSymbol.InstanceConstructors.Single().ThisParameter;
|
|
}
|
|
|
|
public static Symbol ConstructedFrom(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Invalid comparison between Unknown and I4
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000f: Invalid comparison between Unknown and I4
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind != 9)
|
|
{
|
|
if ((int)kind == 11)
|
|
{
|
|
return ((NamedTypeSymbol)symbol).ConstructedFrom;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)symbol.Kind);
|
|
}
|
|
return ((MethodSymbol)symbol).ConstructedFrom;
|
|
}
|
|
|
|
public static bool IsSourceParameterWithEnumeratorCancellationAttribute(this ParameterSymbol parameter)
|
|
{
|
|
if (!(parameter is SourceComplexParameterSymbolBase sourceComplexParameterSymbolBase))
|
|
{
|
|
if (parameter is SynthesizedComplexParameterSymbol synthesizedComplexParameterSymbol)
|
|
{
|
|
return synthesizedComplexParameterSymbol.HasEnumeratorCancellationAttribute;
|
|
}
|
|
return false;
|
|
}
|
|
return sourceComplexParameterSymbolBase.HasEnumeratorCancellationAttribute;
|
|
}
|
|
|
|
public static bool IsContainingSymbolOfAllTypeParameters(this Symbol containingSymbol, TypeSymbol type)
|
|
{
|
|
return (object)type.VisitType(s_hasInvalidTypeParameterFunc, containingSymbol) == null;
|
|
}
|
|
|
|
public static bool IsContainingSymbolOfAllTypeParameters(this Symbol containingSymbol, ImmutableArray<TypeSymbol> types)
|
|
{
|
|
return types.All(containingSymbol.IsContainingSymbolOfAllTypeParameters);
|
|
}
|
|
|
|
private static bool HasInvalidTypeParameter(TypeSymbol type, Symbol? containingSymbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0031: Invalid comparison between Unknown and I4
|
|
if ((int)type.TypeKind == 11)
|
|
{
|
|
Symbol containingSymbol2 = type.ContainingSymbol;
|
|
while ((object)containingSymbol != null && (int)containingSymbol.Kind != 12)
|
|
{
|
|
if (containingSymbol == containingSymbol2)
|
|
{
|
|
return false;
|
|
}
|
|
containingSymbol = containingSymbol.ContainingSymbol;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsTypeOrTypeAlias(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Invalid comparison between Unknown and I4
|
|
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0030: Invalid comparison between Unknown and I4
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0026: Expected I4, but got Unknown
|
|
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0035: Invalid comparison between Unknown and I4
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0029: Invalid comparison between Unknown and I4
|
|
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003a: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind <= 11)
|
|
{
|
|
switch ((int)kind)
|
|
{
|
|
default:
|
|
if ((int)kind == 11)
|
|
{
|
|
break;
|
|
}
|
|
goto IL_004f;
|
|
case 1:
|
|
case 3:
|
|
case 4:
|
|
break;
|
|
case 0:
|
|
return ((AliasSymbol)symbol).Target.IsTypeOrTypeAlias();
|
|
case 2:
|
|
goto IL_004f;
|
|
}
|
|
}
|
|
else if ((int)kind != 14 && (int)kind != 17 && (int)kind != 20)
|
|
{
|
|
goto IL_004f;
|
|
}
|
|
return true;
|
|
IL_004f:
|
|
return false;
|
|
}
|
|
|
|
internal static bool CompilationAllowsUnsafe(this Symbol symbol)
|
|
{
|
|
return symbol.DeclaringCompilation.Options.AllowUnsafe;
|
|
}
|
|
|
|
internal static void CheckUnsafeModifier(this Symbol symbol, DeclarationModifiers modifiers, BindingDiagnosticBag diagnostics)
|
|
{
|
|
symbol.CheckUnsafeModifier(modifiers, symbol.GetFirstLocation(), diagnostics);
|
|
}
|
|
|
|
internal static void CheckUnsafeModifier(this Symbol symbol, DeclarationModifiers modifiers, Location errorLocation, BindingDiagnosticBag diagnostics)
|
|
{
|
|
symbol.CheckUnsafeModifier(modifiers, errorLocation, ((BindingDiagnosticBag)diagnostics).DiagnosticBag);
|
|
}
|
|
|
|
internal static void CheckUnsafeModifier(this Symbol symbol, DeclarationModifiers modifiers, Location errorLocation, DiagnosticBag? diagnostics)
|
|
{
|
|
if (diagnostics != null && (modifiers & DeclarationModifiers.Unsafe) == DeclarationModifiers.Unsafe && !symbol.CompilationAllowsUnsafe())
|
|
{
|
|
diagnostics.Add(ErrorCode.ERR_IllegalUnsafe, errorLocation);
|
|
}
|
|
}
|
|
|
|
public static bool IsHiddenByCodeAnalysisEmbeddedAttribute(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Invalid comparison between Unknown and I4
|
|
NamedTypeSymbol namedTypeSymbol = (((int)symbol.Kind == 11) ? ((NamedTypeSymbol)symbol) : symbol.ContainingType);
|
|
if ((object)namedTypeSymbol == null)
|
|
{
|
|
return false;
|
|
}
|
|
while ((object)namedTypeSymbol.ContainingType != null)
|
|
{
|
|
namedTypeSymbol = namedTypeSymbol.ContainingType;
|
|
}
|
|
return namedTypeSymbol.HasCodeAnalysisEmbeddedAttribute;
|
|
}
|
|
|
|
public static bool MustCallMethodsDirectly(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Invalid comparison between Unknown and I4
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind != 5)
|
|
{
|
|
if ((int)kind == 15)
|
|
{
|
|
return ((PropertySymbol)symbol).MustCallMethodsDirectly;
|
|
}
|
|
return false;
|
|
}
|
|
return ((EventSymbol)symbol).MustCallMethodsDirectly;
|
|
}
|
|
|
|
public static int GetArity(this Symbol? symbol)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000d: Invalid comparison between Unknown and I4
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Invalid comparison between Unknown and I4
|
|
if ((object)symbol != null)
|
|
{
|
|
SymbolKind kind = symbol.Kind;
|
|
if ((int)kind == 9)
|
|
{
|
|
return ((MethodSymbol)symbol).Arity;
|
|
}
|
|
if ((int)kind == 11)
|
|
{
|
|
return ((NamedTypeSymbol)symbol).Arity;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
internal static CSharpSyntaxNode GetNonNullSyntaxNode(this Symbol? symbol)
|
|
{
|
|
if ((object)symbol != null)
|
|
{
|
|
SyntaxReference val = symbol.DeclaringSyntaxReferences.FirstOrDefault();
|
|
if (val == null && symbol.IsImplicitlyDeclared)
|
|
{
|
|
Symbol containingSymbol = symbol.ContainingSymbol;
|
|
if ((object)containingSymbol != null)
|
|
{
|
|
val = containingSymbol.DeclaringSyntaxReferences.FirstOrDefault();
|
|
}
|
|
}
|
|
if (val != null)
|
|
{
|
|
return (CSharpSyntaxNode)(object)val.GetSyntax(default(CancellationToken));
|
|
}
|
|
}
|
|
return (CSharpSyntaxNode)(object)CSharpSyntaxTree.Dummy.GetRoot(default(CancellationToken));
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static Symbol? EnsureCSharpSymbolOrNull(this ISymbol? symbol, string paramName)
|
|
{
|
|
if (!(symbol is Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol symbol2))
|
|
{
|
|
if (symbol != null)
|
|
{
|
|
throw new ArgumentException(CSharpResources.NotACSharpSymbol, paramName);
|
|
}
|
|
return null;
|
|
}
|
|
return symbol2.UnderlyingSymbol;
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static AssemblySymbol? EnsureCSharpSymbolOrNull(this IAssemblySymbol? symbol, string paramName)
|
|
{
|
|
return (AssemblySymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static NamespaceOrTypeSymbol? EnsureCSharpSymbolOrNull(this INamespaceOrTypeSymbol? symbol, string paramName)
|
|
{
|
|
return (NamespaceOrTypeSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static NamespaceSymbol? EnsureCSharpSymbolOrNull(this INamespaceSymbol? symbol, string paramName)
|
|
{
|
|
return (NamespaceSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static TypeSymbol? EnsureCSharpSymbolOrNull(this ITypeSymbol? symbol, string paramName)
|
|
{
|
|
return (TypeSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static NamedTypeSymbol? EnsureCSharpSymbolOrNull(this INamedTypeSymbol? symbol, string paramName)
|
|
{
|
|
return (NamedTypeSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static TypeParameterSymbol? EnsureCSharpSymbolOrNull(this ITypeParameterSymbol? symbol, string paramName)
|
|
{
|
|
return (TypeParameterSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static EventSymbol? EnsureCSharpSymbolOrNull(this IEventSymbol? symbol, string paramName)
|
|
{
|
|
return (EventSymbol)((ISymbol?)(object)symbol).EnsureCSharpSymbolOrNull(paramName);
|
|
}
|
|
|
|
internal static TypeWithAnnotations GetTypeOrReturnType(this Symbol symbol)
|
|
{
|
|
symbol.GetTypeOrReturnType(out RefKind _, out TypeWithAnnotations returnType, out ImmutableArray<CustomModifier> _);
|
|
return returnType;
|
|
}
|
|
|
|
internal static FlowAnalysisAnnotations GetFlowAnalysisAnnotations(this PropertySymbol property)
|
|
{
|
|
FlowAnalysisAnnotations flowAnalysisAnnotations = property.GetOwnOrInheritedGetMethod()?.ReturnTypeFlowAnalysisAnnotations ?? FlowAnalysisAnnotations.None;
|
|
FlowAnalysisAnnotations? flowAnalysisAnnotations2 = property.GetOwnOrInheritedSetMethod()?.Parameters.Last().FlowAnalysisAnnotations;
|
|
if (flowAnalysisAnnotations2.HasValue)
|
|
{
|
|
FlowAnalysisAnnotations valueOrDefault = flowAnalysisAnnotations2.GetValueOrDefault();
|
|
flowAnalysisAnnotations |= valueOrDefault;
|
|
}
|
|
else if (property is SourcePropertySymbolBase sourcePropertySymbolBase)
|
|
{
|
|
if (sourcePropertySymbolBase.HasAllowNull)
|
|
{
|
|
flowAnalysisAnnotations |= FlowAnalysisAnnotations.AllowNull;
|
|
}
|
|
if (sourcePropertySymbolBase.HasDisallowNull)
|
|
{
|
|
flowAnalysisAnnotations |= FlowAnalysisAnnotations.DisallowNull;
|
|
}
|
|
}
|
|
return flowAnalysisAnnotations;
|
|
}
|
|
|
|
internal static FlowAnalysisAnnotations GetFlowAnalysisAnnotations(this Symbol? symbol)
|
|
{
|
|
if (!(symbol is MethodSymbol { ReturnTypeFlowAnalysisAnnotations: var returnTypeFlowAnalysisAnnotations }))
|
|
{
|
|
if (!(symbol is PropertySymbol property))
|
|
{
|
|
if (!(symbol is ParameterSymbol { FlowAnalysisAnnotations: var flowAnalysisAnnotations }))
|
|
{
|
|
if (!(symbol is FieldSymbol { FlowAnalysisAnnotations: var flowAnalysisAnnotations2 }))
|
|
{
|
|
return FlowAnalysisAnnotations.None;
|
|
}
|
|
return flowAnalysisAnnotations2;
|
|
}
|
|
return flowAnalysisAnnotations;
|
|
}
|
|
return property.GetFlowAnalysisAnnotations();
|
|
}
|
|
return returnTypeFlowAnalysisAnnotations;
|
|
}
|
|
|
|
internal static void GetTypeOrReturnType(this Symbol symbol, out RefKind refKind, out TypeWithAnnotations returnType, out ImmutableArray<CustomModifier> refCustomModifiers)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0041: Expected I4, but got Unknown
|
|
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00eb: Expected I4, but got Unknown
|
|
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0077: Expected I4, but got Unknown
|
|
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0115: Expected I4, but got Unknown
|
|
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009f: Expected I4, but got Unknown
|
|
SymbolKind kind = symbol.Kind;
|
|
switch (kind - 4)
|
|
{
|
|
case 2:
|
|
{
|
|
FieldSymbol fieldSymbol = (FieldSymbol)symbol;
|
|
refKind = (RefKind)0;
|
|
returnType = fieldSymbol.TypeWithAnnotations;
|
|
refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
|
|
break;
|
|
}
|
|
case 5:
|
|
{
|
|
MethodSymbol methodSymbol = (MethodSymbol)symbol;
|
|
refKind = (RefKind)(int)methodSymbol.RefKind;
|
|
returnType = methodSymbol.ReturnTypeWithAnnotations;
|
|
refCustomModifiers = methodSymbol.RefCustomModifiers;
|
|
break;
|
|
}
|
|
case 11:
|
|
{
|
|
PropertySymbol propertySymbol = (PropertySymbol)symbol;
|
|
refKind = (RefKind)(int)propertySymbol.RefKind;
|
|
returnType = propertySymbol.TypeWithAnnotations;
|
|
refCustomModifiers = propertySymbol.RefCustomModifiers;
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
EventSymbol eventSymbol = (EventSymbol)symbol;
|
|
refKind = (RefKind)0;
|
|
returnType = eventSymbol.TypeWithAnnotations;
|
|
refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
|
|
break;
|
|
}
|
|
case 4:
|
|
{
|
|
LocalSymbol localSymbol = (LocalSymbol)symbol;
|
|
refKind = (RefKind)(int)localSymbol.RefKind;
|
|
returnType = localSymbol.TypeWithAnnotations;
|
|
refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
|
|
break;
|
|
}
|
|
case 9:
|
|
{
|
|
ParameterSymbol parameterSymbol = (ParameterSymbol)symbol;
|
|
refKind = (RefKind)(int)parameterSymbol.RefKind;
|
|
returnType = parameterSymbol.TypeWithAnnotations;
|
|
refCustomModifiers = parameterSymbol.RefCustomModifiers;
|
|
break;
|
|
}
|
|
case 0:
|
|
refKind = (RefKind)0;
|
|
returnType = TypeWithAnnotations.Create((TypeSymbol)symbol);
|
|
refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
|
|
break;
|
|
default:
|
|
throw ExceptionUtilities.UnexpectedValue((object)symbol.Kind);
|
|
}
|
|
}
|
|
|
|
internal static bool IsImplementableInterfaceMember(this Symbol symbol)
|
|
{
|
|
if (!symbol.IsSealed && (symbol.IsAbstract || symbol.IsVirtual))
|
|
{
|
|
return symbol.ContainingType?.IsInterface ?? false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
internal static bool RequiresInstanceReceiver(this Symbol symbol)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0023: Expected I4, but got Unknown
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0026: Invalid comparison between Unknown and I4
|
|
SymbolKind kind = symbol.Kind;
|
|
switch (kind - 5)
|
|
{
|
|
default:
|
|
if ((int)kind != 15)
|
|
{
|
|
break;
|
|
}
|
|
return ((PropertySymbol)symbol).RequiresInstanceReceiver;
|
|
case 4:
|
|
return ((MethodSymbol)symbol).RequiresInstanceReceiver;
|
|
case 1:
|
|
return ((FieldSymbol)symbol).RequiresInstanceReceiver;
|
|
case 0:
|
|
return ((EventSymbol)symbol).RequiresInstanceReceiver;
|
|
case 2:
|
|
case 3:
|
|
break;
|
|
}
|
|
throw new ArgumentException("only methods, properties, fields and events can take a receiver", "symbol");
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
private static TISymbol? GetPublicSymbol<TISymbol>(this Symbol? symbol) where TISymbol : class, ISymbol
|
|
{
|
|
return (TISymbol)(object)symbol?.ISymbol;
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static ISymbol? GetPublicSymbol(this Symbol? symbol)
|
|
{
|
|
return symbol.GetPublicSymbol<ISymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IMethodSymbol? GetPublicSymbol(this MethodSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IMethodSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IPropertySymbol? GetPublicSymbol(this PropertySymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IPropertySymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static INamedTypeSymbol? GetPublicSymbol(this NamedTypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<INamedTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static INamespaceSymbol? GetPublicSymbol(this NamespaceSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<INamespaceSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static ITypeSymbol? GetPublicSymbol(this TypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<ITypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static ILocalSymbol? GetPublicSymbol(this LocalSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<ILocalSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IAssemblySymbol? GetPublicSymbol(this AssemblySymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IAssemblySymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static INamespaceOrTypeSymbol? GetPublicSymbol(this NamespaceOrTypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<INamespaceOrTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IDiscardSymbol? GetPublicSymbol(this DiscardSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IDiscardSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IFieldSymbol? GetPublicSymbol(this FieldSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IFieldSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IParameterSymbol? GetPublicSymbol(this ParameterSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IParameterSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IRangeVariableSymbol? GetPublicSymbol(this RangeVariableSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IRangeVariableSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static ILabelSymbol? GetPublicSymbol(this LabelSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<ILabelSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IAliasSymbol? GetPublicSymbol(this AliasSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IAliasSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IModuleSymbol? GetPublicSymbol(this ModuleSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IModuleSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static ITypeParameterSymbol? GetPublicSymbol(this TypeParameterSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<ITypeParameterSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IArrayTypeSymbol? GetPublicSymbol(this ArrayTypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IArrayTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IPointerTypeSymbol? GetPublicSymbol(this PointerTypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IPointerTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IFunctionPointerTypeSymbol? GetPublicSymbol(this FunctionPointerTypeSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IFunctionPointerTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static IEventSymbol? GetPublicSymbol(this EventSymbol? symbol)
|
|
{
|
|
return ((Symbol?)symbol).GetPublicSymbol<IEventSymbol>();
|
|
}
|
|
|
|
internal static IEnumerable<ISymbol?> GetPublicSymbols(this IEnumerable<Symbol?> symbols)
|
|
{
|
|
return symbols.Select((Symbol p) => p.GetPublicSymbol<ISymbol>());
|
|
}
|
|
|
|
private static ImmutableArray<TISymbol> GetPublicSymbols<TISymbol>(this ImmutableArray<Symbol> symbols) where TISymbol : class, ISymbol
|
|
{
|
|
if (symbols.IsDefault)
|
|
{
|
|
return default(ImmutableArray<TISymbol>);
|
|
}
|
|
return ImmutableArrayExtensions.SelectAsArray<Symbol, TISymbol>(symbols, (Func<Symbol, TISymbol>)((Symbol p) => p.GetPublicSymbol<TISymbol>()));
|
|
}
|
|
|
|
internal static ImmutableArray<ISymbol> GetPublicSymbols(this ImmutableArray<Symbol> symbols)
|
|
{
|
|
return symbols.GetPublicSymbols<ISymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IPropertySymbol> GetPublicSymbols(this ImmutableArray<PropertySymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<PropertySymbol>(symbols).GetPublicSymbols<IPropertySymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<ITypeSymbol> GetPublicSymbols(this ImmutableArray<TypeSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<TypeSymbol>(symbols).GetPublicSymbols<ITypeSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<INamedTypeSymbol> GetPublicSymbols(this ImmutableArray<NamedTypeSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<NamedTypeSymbol>(symbols).GetPublicSymbols<INamedTypeSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<ILocalSymbol> GetPublicSymbols(this ImmutableArray<LocalSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<LocalSymbol>(symbols).GetPublicSymbols<ILocalSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IEventSymbol> GetPublicSymbols(this ImmutableArray<EventSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<EventSymbol>(symbols).GetPublicSymbols<IEventSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<ITypeParameterSymbol> GetPublicSymbols(this ImmutableArray<TypeParameterSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<TypeParameterSymbol>(symbols).GetPublicSymbols<ITypeParameterSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IParameterSymbol> GetPublicSymbols(this ImmutableArray<ParameterSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<ParameterSymbol>(symbols).GetPublicSymbols<IParameterSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IMethodSymbol> GetPublicSymbols(this ImmutableArray<MethodSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<MethodSymbol>(symbols).GetPublicSymbols<IMethodSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IAssemblySymbol> GetPublicSymbols(this ImmutableArray<AssemblySymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<AssemblySymbol>(symbols).GetPublicSymbols<IAssemblySymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<IFieldSymbol> GetPublicSymbols(this ImmutableArray<FieldSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<FieldSymbol>(symbols).GetPublicSymbols<IFieldSymbol>();
|
|
}
|
|
|
|
internal static ImmutableArray<INamespaceSymbol> GetPublicSymbols(this ImmutableArray<NamespaceSymbol> symbols)
|
|
{
|
|
return StaticCast<Symbol>.From<NamespaceSymbol>(symbols).GetPublicSymbols<INamespaceSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static TSymbol? GetSymbol<TSymbol>(this ISymbol? symbol) where TSymbol : Symbol
|
|
{
|
|
return (TSymbol)(((Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol)(object)symbol)?.UnderlyingSymbol);
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static Symbol? GetSymbol(this ISymbol? symbol)
|
|
{
|
|
return symbol.GetSymbol<Symbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static TypeSymbol? GetSymbol(this ITypeSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<TypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static NamedTypeSymbol? GetSymbol(this INamedTypeSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<NamedTypeSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static AliasSymbol? GetSymbol(this IAliasSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<AliasSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static LocalSymbol? GetSymbol(this ILocalSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<LocalSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static AssemblySymbol? GetSymbol(this IAssemblySymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<AssemblySymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static MethodSymbol? GetSymbol(this IMethodSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<MethodSymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static PropertySymbol? GetSymbol(this IPropertySymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<PropertySymbol>();
|
|
}
|
|
|
|
[return: NotNullIfNotNull("symbol")]
|
|
internal static FunctionPointerTypeSymbol? GetSymbol(this IFunctionPointerTypeSymbol? symbol)
|
|
{
|
|
return ((ISymbol?)(object)symbol).GetSymbol<FunctionPointerTypeSymbol>();
|
|
}
|
|
|
|
internal static bool HasAsyncMethodBuilderAttribute(this Symbol symbol, [NotNullWhen(true)] out object? builderArgument)
|
|
{
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0051: Invalid comparison between Unknown and I4
|
|
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
|
|
ImmutableArray<CSharpAttributeData>.Enumerator enumerator = symbol.GetAttributes().GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
CSharpAttributeData current = enumerator.Current;
|
|
if (current.IsTargetAttribute(symbol, AttributeDescription.AsyncMethodBuilderAttribute) && ((AttributeData)current).CommonConstructorArguments.Length == 1)
|
|
{
|
|
TypedConstant val = ((AttributeData)current).CommonConstructorArguments[0];
|
|
if ((int)((TypedConstant)(ref val)).Kind == 3)
|
|
{
|
|
val = ((AttributeData)current).CommonConstructorArguments[0];
|
|
builderArgument = ((TypedConstant)(ref val)).ValueInternal;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
builderArgument = null;
|
|
return false;
|
|
}
|
|
|
|
internal static bool IsRequired(this Symbol symbol)
|
|
{
|
|
if (symbol is FieldSymbol fieldSymbol)
|
|
{
|
|
if (fieldSymbol.IsRequired)
|
|
{
|
|
goto IL_0026;
|
|
}
|
|
}
|
|
else if (symbol is PropertySymbol { IsRequired: not false })
|
|
{
|
|
goto IL_0026;
|
|
}
|
|
return false;
|
|
IL_0026:
|
|
return true;
|
|
}
|
|
|
|
internal static bool ShouldCheckRequiredMembers(this MethodSymbol method)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Invalid comparison between Unknown and I4
|
|
if ((object)method != null && (int)method.MethodKind == 1)
|
|
{
|
|
return !method.HasSetsRequiredMembers;
|
|
}
|
|
return false;
|
|
}
|
|
}
|