[corlib] Defer TypeInfo instantiation logic in DefinedTypes. Fixes #19082
[mono.git] / mcs / class / corlib / System.Reflection / MonoModule.cs
index e9e709863a9dd33ccd3cb57e734acc03117ef485..f5498565260c528bdb0e57fec3fec7ff6ed0fc26 100644 (file)
@@ -31,6 +31,9 @@ using System.Collections;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Runtime.InteropServices;
+using System.Security.Cryptography.X509Certificates;
+using System.Security;
+using System.Security.Permissions;
 
 
 namespace System.Reflection {
@@ -45,6 +48,70 @@ namespace System.Reflection {
        public partial class Module {
 #endif
 
+               public
+#if NET_4_0
+               override
+#endif
+               Assembly Assembly {
+                       get { return assembly; }
+               }
+
+               public
+#if NET_4_0
+               override
+#endif
+               // Note: we do not ask for PathDiscovery because no path is returned here.
+               // However MS Fx requires it (see FDBK23572 for details).
+               string Name {
+                       get { return name; }
+               }
+       
+               public
+#if NET_4_0
+               override
+#endif
+               string ScopeName {
+                       get { return scopename; }
+               }
+
+               public
+#if NET_4_0
+               override
+#endif
+               int MDStreamVersion {
+                       get {
+                               if (_impl == IntPtr.Zero)
+                                       throw new NotSupportedException ();
+                               return GetMDStreamVersion (_impl);
+                       }
+               }
+
+               public
+#if NET_4_0
+               override
+#endif
+               Guid ModuleVersionId {
+                       get {
+                               return GetModuleVersionId ();
+                       }
+               }
+
+#if NET_4_0
+               public override
+#else
+               public virtual
+#endif
+               string FullyQualifiedName {
+                       get {
+#if !NET_2_1
+                               if (SecurityManager.SecurityEnabled) {
+                                       new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fqname).Demand ();
+                               }
+#endif
+                               return fqname;
+                       }
+               }
+
                public
 #if NET_4_0
                override
@@ -61,12 +128,12 @@ namespace System.Reflection {
 #endif
                Type[] FindTypes(TypeFilter filter, object filterCriteria) 
                {
-                       System.Collections.ArrayList filtered = new System.Collections.ArrayList ();
+                       var filtered = new List<Type> ();
                        Type[] types = GetTypes ();
                        foreach (Type t in types)
                                if (filter (t, filterCriteria))
                                        filtered.Add (t);
-                       return (Type[])filtered.ToArray (typeof(Type));
+                       return filtered.ToArray ();
                }
 
 #if NET_4_0
@@ -117,6 +184,14 @@ namespace System.Reflection {
                        return (globalType != null) ? globalType.GetFields (bindingFlags) : new FieldInfo [0];
                }
 
+#if NET_4_0
+               public override
+#else
+               public virtual
+#endif
+               int MetadataToken {
+                       get { return get_MetadataToken (this); }
+               }
                protected
 #if NET_4_0
                override
@@ -129,7 +204,11 @@ namespace System.Reflection {
                                return null;
 
                        Type globalType = GetGlobalType ();
-                       return (globalType != null) ? globalType.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers) : null;
+                       if (globalType == null)
+                               return null;
+                       if (types == null)
+                               return globalType.GetMethod (name);
+                       return globalType.GetMethod (name, bindingAttr, binder, callConvention, types, modifiers);
                }
 
                public
@@ -262,6 +341,33 @@ namespace System.Reflection {
                                return res;
                }
 
+#if !NET_2_1
+
+               public
+#if NET_4_0
+               override
+#endif
+               X509Certificate GetSignerCertificate ()
+               {
+                       try {
+                               return X509Certificate.CreateFromSignedFile (assembly.Location);
+                       }
+                       catch {
+                               return null;
+                       }
+               }
+#endif
+
+#if NET_4_0
+               public override
+#else
+               public virtual
+#endif
+               Type[] GetTypes() 
+               {
+                       return InternalGetTypes ();
+               }
+
 #if NET_4_0
                public override IList<CustomAttributeData> GetCustomAttributesData () {
                        return CustomAttributeData.GetCustomAttributes (this);