~ruther/NosSmooth

ref: c076813783b2051c6bdf20dd8862d4e322ec88ef NosSmooth/Packets/NosSmooth.PacketSerializersGenerator/Extensions/AttributeListSyntaxExtensions.cs -rw-r--r-- 1.3 KiB
c0768137 — František Boháček feat: split packets definitions into separate assembly 3 years ago
                                                                                
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
//
//  AttributeListSyntaxExtensions.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace NosSmooth.PacketSerializersGenerator.Extensions;

/// <summary>
/// Extension methods for <see cref="AttributeListSyntax"/>.
/// </summary>
public static class AttributeListSyntaxExtensions
{
    /// <summary>
    /// Whether the attribute list contains the attribute with the given full name.
    /// </summary>
    /// <param name="attributeList">The list of the attributes.</param>
    /// <param name="semanticModel">The semantic model.</param>
    /// <param name="attributeFullName">The full name of the attribute.</param>
    /// <returns>Whether the attribute is present.</returns>
    public static bool ContainsAttribute(this AttributeListSyntax attributeList, SemanticModel semanticModel, string attributeFullName)
    {
        var first = semanticModel.GetTypeInfo(attributeList.Attributes[0]).Type?.ToString()!;
        return attributeList.Attributes.Any(x => Regex.IsMatch(semanticModel.GetTypeInfo(x).Type?.ToString()!, attributeFullName));
    }
}
Do not follow this link