Merge pull request #4033 from ntherning/no-stdcall-for-icalls-on-windows-32-bit
[mono.git] / mcs / class / corlib / System.Reflection / Assembly.cs
index c5cecb3858e7d17ef3db6c34fb55db48b3ea6ba2..07df9323e3477d3d216e5e30b2789978630945a8 100644 (file)
@@ -53,12 +53,15 @@ namespace System.Reflection {
        [ClassInterface(ClassInterfaceType.None)]
        [StructLayout (LayoutKind.Sequential)]
 #if MOBILE
-       public partial class Assembly : ICustomAttributeProvider {
+       public partial class Assembly : ICustomAttributeProvider, ISerializable
 #else
-       public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
+       public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable
 #endif
-               internal class ResolveEventHolder {
+       {
+               internal class ResolveEventHolder {     
+#pragma warning disable 67
                        public event ModuleResolveEventHandler ModuleResolve;
+#pragma warning restore
                }
 
                internal class UnmanagedMemoryStreamForModule : UnmanagedMemoryStream
@@ -117,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;
@@ -425,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)
                {
@@ -644,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);
@@ -667,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);
@@ -751,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);
@@ -894,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");