Thanks, Andrew.
On Monday, September 17, 2012 6:16:11 PM UTC+2, Andrew wrote:
The PromotionHelper looks at the [Promote()] attribute on a member, but does not consider the class that contains the member. I would like to suggest a change to the code for PromotionHelper.IsPromoted so that if the member is not explicitly promoted then its containing class is checked for the Promote attribute, and that is used as the value for the member. This would allow an entire class to be Promote(false) except for a selected few explicitly marked members.
This is the code that would do it:
public static bool IsPromoted(MemberInfo member)
{
PromoteAttribute attribute;
if (Cache.TryGetValue(member, out attribute))
return attribute.Promote;
attribute = (PromoteAttribute)Attribute.GetCustomAttribute(member, TargetAttributeType);
if (attribute == null)
{
object[] attrs = member.DeclaringType.GetCustomAttributes(TargetAttributeType, true);
if (attrs != null && attrs.Length > 0)
attribute = attrs[0] as PromoteAttribute;
}
if (attribute == null)
attribute = PromoteAttribute.Yes;
Cache.Add(member, attribute);
return attribute.Promote;
}