/// <summary> /// Finds all custom attributes of a certain type /// </summary> /// <param name="attrType">Custom attribute type</param> /// <param name="options">Attribute type comparison flags</param> /// <returns>All <see cref="CustomAttribute"/>s of the requested type</returns> public IEnumerable <CustomAttribute> FindAll(IType attrType, SigComparerOptions options) { var comparer = new SigComparer(options); foreach (var ca in this.GetSafeEnumerable()) { if (comparer.Equals(ca.AttributeType, attrType)) { yield return(ca); } } }
/// <summary> /// Finds a custom attribute /// </summary> /// <param name="attrType">Custom attribute type</param> /// <param name="options">Attribute type comparison flags</param> /// <returns>The first <see cref="CustomAttribute"/> found or <c>null</c> if none found</returns> public CustomAttribute Find(IType attrType, SigComparerOptions options) { var comparer = new SigComparer(options); foreach (var ca in this.GetSafeEnumerable()) { if (comparer.Equals(ca.AttributeType, attrType)) { return(ca); } } return(null); }
static bool RefEquals(object a, object b) { if (Equals(a, b)) { return(true); } if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) { return(false); } { var pb = b as PropertyDef; if (pb != null) { var tmp = a; a = b; b = tmp; } var eb = b as EventDef; if (eb != null) { var tmp = a; a = b; b = tmp; } } const SigComparerOptions flags = SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.PrivateScopeIsComparable; var type = a as IType; if (type != null) { return(new SigComparer().Equals(type, b as IType)); } var method = a as IMethod; if (method != null && method.IsMethod) { return(new SigComparer(flags).Equals(method, b as IMethod)); } var field = a as IField; if (field != null && field.IsField) { return(new SigComparer(flags).Equals(field, b as IField)); } var prop = a as PropertyDef; if (prop != null) { if (new SigComparer(flags).Equals(prop, b as PropertyDef)) { return(true); } var bm = b as IMethod; return(bm != null && (new SigComparer(flags).Equals(prop.GetMethod, bm) || new SigComparer(flags).Equals(prop.SetMethod, bm))); } var evt = a as EventDef; if (evt != null) { if (new SigComparer(flags).Equals(evt, b as EventDef)) { return(true); } var bm = b as IMethod; return(bm != null && (new SigComparer(flags).Equals(evt.AddMethod, bm) || new SigComparer(flags).Equals(evt.InvokeMethod, bm) || new SigComparer(flags).Equals(evt.RemoveMethod, bm))); } Debug.Fail("Shouldn't be here"); return(false); }