Beispiel #1
0
        internal object[] GetPseudoCustomAttributes()
        {
            int count = 0;

            /* MS.NET doesn't report MethodImplAttribute */

            MonoMethodInfo info = MonoMethodInfo.GetMethodInfo(mhandle);

            if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
            {
                count++;
            }
            if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
            {
                count++;
            }

            if (count == 0)
            {
                return(null);
            }
            object[] attrs = new object [count];
            count = 0;

            if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
            {
                attrs [count++] = new PreserveSigAttribute();
            }
            if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
            {
                attrs [count++] = DllImportAttribute.GetCustomAttribute(this);
            }

            return(attrs);
        }
        internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, Type caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = (caType == typeof(object)) || (caType == typeof(Attribute));

            if ((!flag && (s_pca[caType] == null)) && !IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();
            Attribute        item = null;

            if (flag || (caType == typeof(DllImportAttribute)))
            {
                item = DllImportAttribute.GetCustomAttribute(method);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if (flag || (caType == typeof(PreserveSigAttribute)))
            {
                item = PreserveSigAttribute.GetCustomAttribute(method);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if (includeSecCa && (flag || IsSecurityAttribute(caType)))
            {
                object[] objArray;
                GetSecurityAttributes(method.Module.ModuleHandle, method.MetadataToken, out objArray);
                if (objArray != null)
                {
                    foreach (object obj2 in objArray)
                    {
                        if ((caType == obj2.GetType()) || obj2.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj2);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }
Beispiel #3
0
        internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null && !PseudoCustomAttribute.IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();

            if (flag || caType == (RuntimeType)typeof(DllImportAttribute))
            {
                Attribute customAttribute = DllImportAttribute.GetCustomAttribute(method);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (flag || caType == (RuntimeType)typeof(PreserveSigAttribute))
            {
                Attribute customAttribute = PreserveSigAttribute.GetCustomAttribute(method);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType)))
            {
                object[] array;
                PseudoCustomAttribute.GetSecurityAttributes(method.Module.ModuleHandle.GetRuntimeModule(), method.MetadataToken, false, out array);
                if (array != null)
                {
                    foreach (object obj in array)
                    {
                        if (caType == obj.GetType() || obj.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }