diff --git a/src/DotNet/CustomAttributeCollection.cs b/src/DotNet/CustomAttributeCollection.cs index 29a6e1c40..daa83c82f 100644 --- a/src/DotNet/CustomAttributeCollection.cs +++ b/src/DotNet/CustomAttributeCollection.cs @@ -1,116 +1,116 @@ -// dnlib: See LICENSE.txt for more info - -using System.Collections.Generic; -using dnlib.Utils; -using System; - -namespace dnlib.DotNet { - /// - /// Stores s - /// - public class CustomAttributeCollection : LazyList { - /// - /// Default constructor - /// - public CustomAttributeCollection() { - } - - /// - /// Constructor - /// - /// Initial length of the list - /// Context passed to - /// Delegate instance that returns original values - public CustomAttributeCollection(int length, object context, Func readOriginalValue) - : base(length, context, readOriginalValue) { - } - - /// - /// Checks whether a custom attribute is present - /// - /// Full name of custom attribute type - /// true if the custom attribute type is present, false otherwise - public bool IsDefined(string fullName) => Find(fullName) is not null; - - /// - /// Removes all custom attributes of a certain type - /// - /// Full name of custom attribute type that should be removed - public void RemoveAll(string fullName) { - for (int i = Count - 1; i >= 0; i--) { - var ca = this[i]; - if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) - RemoveAt(i); - } - } - - /// - /// Finds a custom attribute - /// - /// Full name of custom attribute type - /// A or null if it wasn't found - public CustomAttribute Find(string fullName) { - foreach (var ca in this) { - if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) - return ca; - } - - return null; - } - - /// - /// Finds all custom attributes of a certain type - /// - /// Full name of custom attribute type - /// All s of the requested type - public IEnumerable FindAll(string fullName) { - foreach (var ca in this) { - if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) - yield return ca; - } - } - - /// - /// Finds a custom attribute - /// - /// Custom attribute type - /// The first found or null if none found - public CustomAttribute Find(IType attrType) => Find(attrType, 0); - - /// - /// Finds a custom attribute - /// - /// Custom attribute type - /// Attribute type comparison flags - /// The first found or null if none found - public CustomAttribute Find(IType attrType, SigComparerOptions options) { - var comparer = new SigComparer(options); - foreach (var ca in this) { - if (comparer.Equals(ca.AttributeType, attrType)) - return ca; - } - return null; - } - - /// - /// Finds all custom attributes of a certain type - /// - /// Custom attribute type - /// All s of the requested type - public IEnumerable FindAll(IType attrType) => FindAll(attrType, 0); - - /// - /// Finds all custom attributes of a certain type - /// - /// Custom attribute type - /// Attribute type comparison flags - /// All s of the requested type - public IEnumerable FindAll(IType attrType, SigComparerOptions options) { - var comparer = new SigComparer(options); - foreach (var ca in this) { - if (comparer.Equals(ca.AttributeType, attrType)) - yield return ca; - } - } - } -} +// dnlib: See LICENSE.txt for more info + +using System.Collections.Generic; +using dnlib.Utils; +using System; + +namespace dnlib.DotNet { + /// + /// Stores s + /// + public class CustomAttributeCollection : LazyList { + /// + /// Default constructor + /// + public CustomAttributeCollection() { + } + + /// + /// Constructor + /// + /// Initial length of the list + /// Context passed to + /// Delegate instance that returns original values + public CustomAttributeCollection(int length, object context, Func readOriginalValue) + : base(length, context, readOriginalValue) { + } + + /// + /// Checks whether a custom attribute is present + /// + /// Full name of custom attribute type + /// true if the custom attribute type is present, false otherwise + public bool IsDefined(string fullName) => Find(fullName) is not null; + + /// + /// Removes all custom attributes of a certain type + /// + /// Full name of custom attribute type that should be removed + public void RemoveAll(string fullName) { + for (int i = Count - 1; i >= 0; i--) { + var ca = this[i]; + if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) + RemoveAt(i); + } + } + + /// + /// Finds a custom attribute + /// + /// Full name of custom attribute type + /// A or null if it wasn't found + public CustomAttribute Find(string fullName) { + foreach (var ca in this) { + if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) + return ca; + } + + return null; + } + + /// + /// Finds all custom attributes of a certain type + /// + /// Full name of custom attribute type + /// All s of the requested type + public IEnumerable FindAll(string fullName) { + foreach (var ca in this) { + if (ca is not null && fullName.EndsWith(ca.TypeName, StringComparison.Ordinal) && ca.TypeFullName == fullName) + yield return ca; + } + } + + /// + /// Finds a custom attribute + /// + /// Custom attribute type + /// The first found or null if none found + public CustomAttribute Find(IType attrType) => Find(attrType, 0); + + /// + /// Finds a custom attribute + /// + /// Custom attribute type + /// Attribute type comparison flags + /// The first found or null if none found + public CustomAttribute Find(IType attrType, SigComparerOptions options) { + var comparer = new SigComparer(options); + foreach (var ca in this) { + if (comparer.Equals(ca.AttributeType, attrType)) + return ca; + } + return null; + } + + /// + /// Finds all custom attributes of a certain type + /// + /// Custom attribute type + /// All s of the requested type + public IEnumerable FindAll(IType attrType) => FindAll(attrType, 0); + + /// + /// Finds all custom attributes of a certain type + /// + /// Custom attribute type + /// Attribute type comparison flags + /// All s of the requested type + public IEnumerable FindAll(IType attrType, SigComparerOptions options) { + var comparer = new SigComparer(options); + foreach (var ca in this) { + if (comparer.Equals(ca.AttributeType, attrType)) + yield return ca; + } + } + } +}