-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathISymbolExtensions.cs
More file actions
33 lines (29 loc) · 1.24 KB
/
ISymbolExtensions.cs
File metadata and controls
33 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using Microsoft.CodeAnalysis;
namespace ReactiveUI.SourceGenerators.Extensions;
/// <summary>
/// Extension methods for the <see cref="ISymbol"/> type.
/// </summary>
internal static class ISymbolExtensions
{
/// <summary>
/// Checks whether or not a given symbol has an attribute with the specified fully qualified metadata name.
/// </summary>
/// <param name="symbol">The input <see cref="ISymbol"/> instance to check.</param>
/// <param name="name">The attribute name to look for.</param>
/// <returns>Whether or not <paramref name="symbol"/> has an attribute with the specified name.</returns>
public static bool HasAttributeWithFullyQualifiedMetadataName(this ISymbol symbol, string name)
{
foreach (var attribute in symbol.GetAttributes())
{
if (attribute.AttributeClass?.HasFullyQualifiedMetadataName(name) == true)
{
return true;
}
}
return false;
}
}