Merge pull request #4033 from ntherning/no-stdcall-for-icalls-on-windows-32-bit
[mono.git] / mcs / class / corlib / System.Reflection / Assembly.cs
index e436c8dbc385a2ac902ffcbc115e0f618629ed95..07df9323e3477d3d216e5e30b2789978630945a8 100644 (file)
@@ -120,7 +120,7 @@ namespace System.Reflection {
                // We can't store the event directly in this class, since the
                // compiler would silently insert the fields before _mono_assembly
                //
-               public event ModuleResolveEventHandler ModuleResolve {
+               public virtual event ModuleResolveEventHandler ModuleResolve {
                        [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
                        add {
                                resolve_event_holder.ModuleResolve += value;
@@ -428,7 +428,7 @@ namespace System.Reflection {
                internal extern Type InternalGetType (Module module, String name, Boolean throwOnError, Boolean ignoreCase);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               internal extern static void InternalGetAssemblyName (string assemblyFile, AssemblyName aname);
+               internal extern unsafe static void InternalGetAssemblyName (string assemblyFile, out Mono.MonoAssemblyName aname, out string codebase);
 
                public virtual AssemblyName GetName (Boolean copiedName)
                {
@@ -647,7 +647,7 @@ namespace System.Reflection {
                        return LoadFrom (assemblyFile, true);
                }
 
-               [Obsolete]
+        [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
                public static Assembly LoadWithPartialName (string partialName)
                {
                        return LoadWithPartialName (partialName, null);
@@ -670,7 +670,7 @@ namespace System.Reflection {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private static extern Assembly load_with_partial_name (string name, Evidence e);
 
-               [Obsolete]
+        [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
                public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
                {
                        return LoadWithPartialName (partialName, securityEvidence, true);
@@ -754,7 +754,37 @@ namespace System.Reflection {
                public extern static Assembly GetCallingAssembly ();
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               internal static extern AssemblyName[] GetReferencedAssemblies (Assembly module);
+               internal static extern IntPtr InternalGetReferencedAssemblies (Assembly module);
+
+               internal static AssemblyName[] GetReferencedAssemblies (Assembly module)
+               {
+                       using (var nativeNames = new Mono.SafeGPtrArrayHandle (InternalGetReferencedAssemblies (module))) {
+                               var numAssemblies = nativeNames.Length;
+                               try {
+                                       AssemblyName [] result = new AssemblyName[numAssemblies];
+                                       const bool addVersion = true;
+                                       const bool addPublicKey = false;
+                                       const bool defaultToken = true;
+                                       const bool assemblyRef = true;
+                                       for (int i = 0; i < numAssemblies; i++) {
+                                               AssemblyName name = new AssemblyName ();
+                                               unsafe {
+                                                       Mono.MonoAssemblyName *nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
+                                                       name.FillName (nativeName, null, addVersion, addPublicKey, defaultToken, assemblyRef);
+                                                       result[i] = name;
+                                               }
+                                       }
+                                       return result;
+                               } finally {
+                                       for (int i = 0; i < numAssemblies; i++) {
+                                               unsafe {
+                                                       Mono.MonoAssemblyName* nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
+                                                       Mono.RuntimeMarshal.FreeAssemblyName (ref *nativeName, true);
+                                               }
+                                       }
+                               }
+                       }
+               }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private extern bool GetManifestResourceInfoInternal (String name, ManifestResourceInfo info);
@@ -897,13 +927,12 @@ namespace System.Reflection {
                public virtual PermissionSet PermissionSet {
                        get { return this.GrantedPermissionSet; }
                }
-               
+#endif
+
                public virtual SecurityRuleSet SecurityRuleSet {
                        get { throw CreateNIE (); }
                }
 
-#endif
-
                static Exception CreateNIE ()
                {
                        return new NotImplementedException ("Derived classes must implement it");