[corlib] Fixes build with old UnmanagedMemoryStream
[mono.git] / mcs / class / corlib / System.Reflection / Assembly.cs
index 5401c0b7bcafff392dc649c0737d0a32a8925e9c..c3bb5a3fbf10cd6c2983d638f4e374d6bec8f2ed 100644 (file)
@@ -58,6 +58,31 @@ namespace System.Reflection {
                        public event ModuleResolveEventHandler ModuleResolve;
                }
 
+               internal class UnmanagedMemoryStreamForModule : UnmanagedMemoryStream
+               {
+                       Module module;
+
+                       public unsafe UnmanagedMemoryStreamForModule (byte* pointer, long length, Module module)
+                               : base (pointer, length)
+                       {
+                               this.module = module;
+                       }
+
+                       protected override void Dispose (bool disposing)
+                       {
+                               if (!closed) {
+                                       /* 
+                                        * The returned pointer points inside metadata, so
+                                        * we have to increase the refcount of the module, and decrease
+                                        * it when the stream is finalized.
+                                        */
+                                       module = null;
+                               }
+
+                               base.Dispose (disposing);
+                       }
+               }
+
                // Note: changes to fields must be reflected in _MonoReflectionAssembly struct (object-internals.h)
 #pragma warning disable 649
                private IntPtr _mono_assembly;
@@ -201,13 +226,9 @@ namespace System.Reflection {
                        }
                }
 
-               [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
                {
-                       if (info == null)
-                               throw new ArgumentNullException ("info");
-
-                       UnitySerializationHolder.GetAssemblyData (this, info, context);
+                       throw new NotImplementedException ();
                }
 
                public virtual bool IsDefined (Type attributeType, bool inherit)
@@ -308,14 +329,8 @@ namespace System.Reflection {
                        else {
                                UnmanagedMemoryStream stream;
                                unsafe {
-                                       stream = new UnmanagedMemoryStream ((byte*) data, size);
+                                       stream = new UnmanagedMemoryStreamForModule ((byte*) data, size, module);
                                }
-                               /* 
-                                * The returned pointer points inside metadata, so
-                                * we have to increase the refcount of the module, and decrease
-                                * it when the stream is finalized.
-                                */
-                               stream.Closed += new EventHandler (new ResourceCloseHandler (module).OnClose);
                                return stream;
                        }
                }
@@ -709,21 +724,6 @@ namespace System.Reflection {
                                return null;
                }
 
-               private class ResourceCloseHandler {
-#pragma warning disable 169, 414
-                       Module module;
-#pragma warning restore 169, 414                       
-
-                       public ResourceCloseHandler (Module module) {
-                               this.module = module;
-                       }
-
-                       public void OnClose (object sender, EventArgs e) {
-                               // The module dtor will take care of things
-                               module = null;
-                       }
-               }
-
                [MonoTODO ("Currently it always returns zero")]
                [ComVisible (false)]
                public