[corlib] Type from reference sources
[mono.git] / mcs / class / corlib / System / MonoCustomAttrs.cs
index d5d5a8a4b16d17c84af1ed767d372e8aeb26731b..f69fe0c1c28b83f1f488c61e65bcbc38f8f3d9fd 100644 (file)
@@ -34,6 +34,7 @@ using System;
 using System.Reflection;
 using System.Collections;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 #if !FULL_AOT_RUNTIME
 using System.Reflection.Emit;
 #endif
@@ -79,7 +80,7 @@ namespace System
                        else if (obj is ParameterInfo)
                                pseudoAttrs = ((ParameterInfo)obj).GetPseudoCustomAttributes ();
                        else if (obj is Type)
-                               pseudoAttrs = ((Type)obj).GetPseudoCustomAttributes ();
+                               pseudoAttrs = GetPseudoCustomAttributes (((Type)obj));
 
                        if ((attributeType != null) && (pseudoAttrs != null)) {
                                for (int i = 0; i < pseudoAttrs.Length; ++i)
@@ -94,6 +95,30 @@ namespace System
                        return pseudoAttrs;
                }
 
+               static object[] GetPseudoCustomAttributes (Type type)
+               {
+                       int count = 0;
+                       var Attributes = type.Attributes;
+
+                       /* IsSerializable returns true for delegates/enums as well */
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               count ++;
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               count ++;
+
+                       if (count == 0)
+                               return null;
+                       object[] attrs = new object [count];
+                       count = 0;
+
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               attrs [count ++] = new SerializableAttribute ();
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               attrs [count ++] = new ComImportAttribute ();
+
+                       return attrs;
+               }
+
                internal static object[] GetCustomAttributesBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
                {
                        object[] attrs;