// // Returns custom attributes for the type. // internal IEnumerable GetCustomAttributes(Type type) { Fx.Assert(type != null, "type parameter is null"); AttributeList attributes = GetExpandedAttributes(type, null, delegate(Type typeToGet, object callbackParam) { TypeMetadata md; if (_metadata.TryGetValue(typeToGet, out md)) { return(md.TypeAttributes); } return(null); }); if (attributes != null) { return(attributes.AsReadOnly()); } return(_empty); }
// // Returns custom attributes for the member. // internal IEnumerable GetCustomAttributes(Type ownerType, string memberName) { Fx.Assert(ownerType != null && memberName != null, "ownerType or memberName parameter is null"); AttributeList attributes = GetExpandedAttributes(ownerType, memberName, delegate(Type typeToGet, object callbackParam) { string name = (string)callbackParam; TypeMetadata md; if (_metadata.TryGetValue(typeToGet, out md)) { // If member attributes are null but type attributes are not, // it is possible that expanding type attributes could cause // member attributes to be added. Check. if (md.MemberAttributes == null && md.TypeAttributes != null && !md.TypeAttributes.IsExpanded) { ExpandAttributes(ownerType, md.TypeAttributes); } if (md.MemberAttributes != null) { AttributeList list; if (md.MemberAttributes.TryGetValue(name, out list)) { return(list); } } } return(null); }); if (attributes != null) { return(attributes.AsReadOnly()); } return(_empty); }