Skip to content

Commit b631a6c

Browse files
committed
Minor code refactoring to some extensions
1 parent 717d602 commit b631a6c

File tree

1 file changed

+15
-15
lines changed
  • components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Extensions

1 file changed

+15
-15
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Extensions/AttributeDataExtensions.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ internal static class AttributeDataExtensions
2222
/// <returns>The resulting location for <paramref name="attributeData"/>, if a syntax reference is available.</returns>
2323
public static Location? GetLocation(this AttributeData attributeData)
2424
{
25-
if (attributeData.ApplicationSyntaxReference is { } syntaxReference)
25+
if (attributeData.ApplicationSyntaxReference is not { } syntaxReference)
2626
{
27-
return syntaxReference.SyntaxTree.GetLocation(syntaxReference.Span);
27+
return null;
2828
}
2929

30-
return null;
30+
return syntaxReference.SyntaxTree.GetLocation(syntaxReference.Span);
3131
}
3232

3333
/// <summary>
@@ -39,25 +39,25 @@ internal static class AttributeDataExtensions
3939
/// <returns>The resulting location for <paramref name="attributeData"/>, if a syntax reference is available.</returns>
4040
public static Location? GetNamedArgumentOrAttributeLocation(this AttributeData attributeData, string name, CancellationToken token = default)
4141
{
42-
if (attributeData.ApplicationSyntaxReference is { } syntaxReference)
42+
if (attributeData.ApplicationSyntaxReference is not { } syntaxReference)
4343
{
44-
// If we can recover the syntax node, look for the target named argument
45-
if (syntaxReference.GetSyntax(token) is AttributeSyntax { ArgumentList: { } argumentList })
44+
return null;
45+
}
46+
47+
// If we can recover the syntax node, look for the target named argument
48+
if (syntaxReference.GetSyntax(token) is AttributeSyntax { ArgumentList: { } argumentList })
49+
{
50+
foreach (AttributeArgumentSyntax argument in argumentList.Arguments)
4651
{
47-
foreach (AttributeArgumentSyntax argument in argumentList.Arguments)
52+
if (argument.NameEquals?.Name.Identifier.Text == name)
4853
{
49-
if (argument.NameEquals?.Name.Identifier.Text == name)
50-
{
51-
return argument.GetLocation();
52-
}
54+
return argument.GetLocation();
5355
}
5456
}
55-
56-
// Otherwise, fallback to the location of the whole attribute
57-
return syntaxReference.SyntaxTree.GetLocation(syntaxReference.Span);
5857
}
5958

60-
return null;
59+
// Otherwise, fallback to the location of the whole attribute
60+
return syntaxReference.SyntaxTree.GetLocation(syntaxReference.Span);
6161
}
6262

6363
/// <summary>

0 commit comments

Comments
 (0)