Ejemplo n.º 1
0
        static internal Object[] GetCustomAttributes(MemberInfo member, Type caType, bool inherit)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            CustomAttribute caItem = GetCustomAttributeList(member, caType, null, 0);

            // if we are asked to go up the hierarchy chain we have to do it now and regardless of the
            // attribute usage for the specific attribute because a derived attribute may ovveride the usage...

            // ... however if the attribute is sealed we can rely on the attribute usage
            if (caType != null && caType.IsSealed && inherit)
            {
                AttributeUsageAttribute usage = CustomAttribute.GetAttributeUsage(caType);
                if (!usage.Inherited)
                {
                    inherit = false; // kill the inheritance request, the attribute does not allow for it
                }
            }

            if (inherit)
            {
                // walk up the inheritance chain and keep accumulating attributes
                int level = 1;
                switch (member.MemberType)
                {
                case MemberTypes.Method:
                {
                    RuntimeMethodInfo baseMethod = ((MethodInfo)member).GetParentDefinition() as RuntimeMethodInfo;
                    while (baseMethod != null)
                    {
                        caItem     = GetCustomAttributeList(baseMethod, caType, caItem, level++);
                        baseMethod = baseMethod.GetParentDefinition() as RuntimeMethodInfo;
                    }
                    break;
                }

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType:
                {
                    RuntimeType baseType = ((Type)member).BaseType as RuntimeType;
                    while (baseType != null)
                    {
                        caItem   = GetCustomAttributeList((MemberInfo)baseType, caType, caItem, level++);
                        baseType = ((Type)baseType).BaseType as RuntimeType;
                    }
                    break;
                }
                }
            }
            return(CustomAttribute.CheckConsistencyAndCreateArray(caItem, caType));
        }
Ejemplo n.º 2
0
        static internal Object[] GetCAReturnValue(RuntimeMethodInfo method, Type caType, bool inherit)
        {
            int token = CustomAttribute.GetMethodRetValueToken(method);

            if (token != 0)
            {
                IntPtr          module = CustomAttribute.GetMemberModule(method, MemberTypes.Method);
                CustomAttribute caItem = CustomAttribute.GetCustomAttributeListCheckType(token, module, caType, null, 0);
                return(CustomAttribute.CheckConsistencyAndCreateArray(caItem, caType));
            }
            return((caType == null || caType.IsValueType) ? s_gObjectEmptyArray : (Object[])Array.CreateInstance(caType, 0));
        }
Ejemplo n.º 3
0
        static internal Object[] GetCustomAttributes(ParameterInfo param, Type caType, bool inherit)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }

            int             token  = param.GetToken();
            IntPtr          module = param.GetModule();
            CustomAttribute caItem = CustomAttribute.GetCustomAttributeListCheckType(token, module, caType, null, 0);

            return(CustomAttribute.CheckConsistencyAndCreateArray(caItem, caType));
        }
Ejemplo n.º 4
0
        static internal Object[] GetCustomAttributes(Module module, Type caType)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            int token = CustomAttribute.GetModuleToken(module);

            if (token != 0)
            {
                IntPtr          mod    = CustomAttribute.GetModuleModule(module);
                CustomAttribute caItem = CustomAttribute.GetCustomAttributeListCheckType(token, mod, caType, null, 0);
                return(CustomAttribute.CheckConsistencyAndCreateArray(caItem, caType));
            }
            return((caType == null || caType.IsValueType) ? s_gObjectEmptyArray : (Object[])Array.CreateInstance(caType, 0));
        }