Skip to content

Commit

Permalink
Simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Apr 26, 2020
1 parent c14d313 commit 86b8a38
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions ReflectionAnalyzers/Helpers/NameOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ internal static bool TryGetExpressionText(ReflectedMember member, SyntaxNodeAnal
targetName = null;
if (member.Symbol is null ||
!member.Symbol.CanBeReferencedByName ||
!context.SemanticModel.IsAccessible(context.Node.SpanStart, member.Symbol) ||
member.Symbol is INamedTypeSymbol { IsGenericType: true } ||
(member.Symbol is IMethodSymbol method && method.MethodKind != MethodKind.Ordinary))
{
return false;
}

if (member.Symbol.ContainingType.IsAnonymousType)
if (member.Symbol is { ContainingType: { IsAnonymousType: true } })
{
if (member.TypeSource is InvocationExpressionSyntax getType &&
getType.TryGetTarget(KnownSymbol.Object.GetType, context.SemanticModel, context.CancellationToken, out _) &&
Expand All @@ -35,11 +37,12 @@ internal static bool TryGetExpressionText(ReflectedMember member, SyntaxNodeAnal
return false;
}

if (!context.SemanticModel.IsAccessible(context.Node.SpanStart, member.Symbol) ||
member.Symbol is INamedTypeSymbol { IsGenericType: true } ||
member.Symbol is IMethodSymbol { AssociatedSymbol: { } })
if (member.Symbol is { ContainingType: { TupleUnderlyingType: { } tupleType } })
{
return false;
targetName = member.Symbol is IFieldSymbol { CorrespondingTupleField: { } tupleField }
? $"{TypeOfString(tupleType)}.{tupleField.Name}"
: $"{TypeOfString(tupleType)}.{member.Symbol.Name}";
return true;
}

if (context.ContainingSymbol.ContainingType.IsAssignableTo(member.Symbol.ContainingType, context.Compilation))
Expand All @@ -54,14 +57,6 @@ member.Symbol is ITypeSymbol ||
return true;
}

if (member.Symbol.ContainingType.TupleUnderlyingType is { } tupleType)
{
targetName = member.Symbol is IFieldSymbol { CorrespondingTupleField: { } tupleField }
? $"{TypeOfString(tupleType)}.{tupleField.Name}"
: $"{TypeOfString(tupleType)}.{member.Symbol.Name}";
return true;
}

targetName = $"{TypeOfString(member.Symbol.ContainingType)}.{member.Symbol.Name}";
return true;

Expand Down

0 comments on commit 86b8a38

Please sign in to comment.