예제 #1
0
        /// <summary>
        ///   Attributes should be replicated if they are non-inheritable,
        ///   but there are some special cases where the attributes means
        ///   something to the CLR, where they should be skipped.
        /// </summary>
        private static bool ShouldSkipAttributeReplication(Type attribute, bool ignoreInheritance)
        {
            if (attribute.GetTypeInfo().IsPublic == false)
            {
                return(true);
            }

            if (AttributesToAvoidReplicating.ShouldAvoid(attribute))
            {
                return(true);
            }

            // Later, there might be more special cases requiring attribute replication,
            // which might justify creating a `SpecialCaseAttributeThatShouldBeReplicated`
            // method and an `AttributesToAlwaysReplicate` class. For the moment, `Param-
            // ArrayAttribute` is the only special case, so keep it simple for now:
            if (attribute == typeof(ParamArrayAttribute))
            {
                return(false);
            }

            if (!ignoreInheritance)
            {
                var attrs = attribute.GetTypeInfo().GetCustomAttributes <AttributeUsageAttribute>(true).ToArray();
                if (attrs.Length != 0)
                {
                    return(attrs[0].Inherited);
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
 private static bool SpecialCaseAttributeThatShouldNotBeReplicated(Type attribute)
 {
     return(AttributesToAvoidReplicating.ShouldAvoid(attribute));
 }