<commit_before>using System.Collections.Generic;
using System.Linq;

namespace AsmResolver.DotNet
{
    /// <summary>
    /// Represents a member that can be referenced by a HasCustomAttribute coded index,
    /// </summary>
    public interface IHasCustomAttribute : IMetadataMember
    {
        /// <summary>
        /// Gets a collection of custom attributes assigned to this member.
        /// </summary>
        IList<CustomAttribute> CustomAttributes { get; }
    }

    /// <summary>
    /// Provides extensions for various metadata members. 
    /// </summary>
    public static partial class Extensions
    {
        /// <summary>
        /// Indicates whether the specified member is compiler generated.
        /// </summary>
        /// <param name="attribute">The referenced member to check</param>
        /// <returns><c>true</c> if the member was generated by the compiler, otherwise <c>false</c></returns>
        public static bool IsCompilerGenerated(this IHasCustomAttribute attribute)
        {
            return attribute.CustomAttributes.Any(c =>
                c.Constructor.DeclaringType.IsTypeOf("System.Runtime.CompilerServices", "CompilerGeneratedAttribute"));
        }
    }
}<commit_msg>Add FindCustomAttributes method.<commit_after>using System.Collections.Generic;
using System.Linq;

namespace AsmResolver.DotNet
{
    /// <summary>
    /// Represents a member that can be referenced by a HasCustomAttribute coded index,
    /// </summary>
    public interface IHasCustomAttribute : IMetadataMember
    {
        /// <summary>
        /// Gets a collection of custom attributes assigned to this member.
        /// </summary>
        IList<CustomAttribute> CustomAttributes { get; }
    }

    /// <summary>
    /// Provides extensions for various metadata members. 
    /// </summary>
    public static partial class Extensions
    {
        /// <summary>
        /// Finds all custom attributes that were assigned to a metadata member that match a particular namespace and name.  
        /// </summary>
        /// <param name="self">The metadata member.</param>
        /// <param name="ns">The namespace of the attribute type.</param>
        /// <param name="name">The name of the attribute type.</param>
        /// <returns>The matching attributes.</returns>
        public static IEnumerable<CustomAttribute> FindCustomAttributes(this IHasCustomAttribute self, string ns, string name)
        {
            foreach (var attribute in self.CustomAttributes)
            {
                var declaringType = attribute.Constructor?.DeclaringType;
                if (declaringType is null)
                    continue;

                if (declaringType.IsTypeOf(ns, name))
                    yield return attribute;
            }
        }

        /// <summary>
        /// Indicates whether the specified member is compiler generated.
        /// </summary>
        /// <param name="self">The referenced member to check</param>
        /// <returns><c>true</c> if the member was generated by the compiler, otherwise <c>false</c></returns>
        public static bool IsCompilerGenerated(this IHasCustomAttribute self) => self
            .FindCustomAttributes("System.Runtime.CompilerServices", "CompilerGeneratedAttribute")
            .Any();
    }
}
{'fraction_non_alphanumeric': 0.10408042578356003, 'fraction_numerical': 0.0, 'mean_word_length': 2.097985347985348, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5891446', 'n_tokens_mistral': 808, 'n_tokens_neox': 783, 'n_words': 250}