Re: Suggest modification to PromotionHelper

12 views
Skip to first unread message

piter....@gmail.com

unread,
Sep 18, 2012, 2:40:25 PM9/18/12
to ssh...@googlegroups.com
Thanks, Andrew.

 I have created an enhancement request, you can see it here  https://github.com/PetroProtsyk/SSharp/issues/27

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;
    }



Reply all
Reply to author
Forward
0 new messages