New test.
[mono.git] / mcs / class / corlib / System.Reflection / Assembly.cs
index 86b8266eafd20fef275480c117fa5ab1257647c8..2442e925b960ebc00658853278a1db1651c7b668 100644 (file)
@@ -38,6 +38,7 @@ using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Collections;
+using System.Collections.Generic;
 using System.Configuration.Assemblies;
 
 using Mono.Security;
@@ -51,11 +52,12 @@ namespace System.Reflection {
        [Serializable]
        [ClassInterface(ClassInterfaceType.None)]
 #if NET_2_1
-       public class Assembly : ICustomAttributeProvider, _Assembly {
+       public partial class Assembly : ICustomAttributeProvider, _Assembly {
+#elif NET_4_0
+       public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
 #else
-       public class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
+       public partial class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
 #endif
-
                internal class ResolveEventHolder {
                        public event ModuleResolveEventHandler ModuleResolve;
                }
@@ -75,7 +77,12 @@ namespace System.Reflection {
                private bool fromByteArray;
                private string assemblyName;
 
-               internal Assembly () 
+#if NET_4_0
+               protected
+#else
+               internal
+#endif
+               Assembly () 
                {
                        resolve_event_holder = new ResolveEventHolder ();
                }
@@ -145,7 +152,7 @@ namespace System.Reflection {
                        [MethodImplAttribute (MethodImplOptions.InternalCall)]
                        get;
                }
-#if !NET_2_1 || MONOTOUCH
+#if !MOONLIGHT
                public virtual Evidence Evidence {
                        [SecurityPermission (SecurityAction.Demand, ControlEvidence = true)]
                        get { return UnprotectedGetEvidence (); }
@@ -165,13 +172,8 @@ namespace System.Reflection {
                }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               private extern bool get_global_assembly_cache ();
+               internal extern bool get_global_assembly_cache ();
 
-               public bool GlobalAssemblyCache {
-                       get {
-                               return get_global_assembly_cache ();
-                       }
-               }
 #endif
                internal bool FromByteArray {
                        set { fromByteArray = value; }
@@ -291,7 +293,7 @@ namespace System.Reflection {
 
                                string location = Path.GetDirectoryName (Location);
                                string filename = Path.Combine (location, info.FileName);
-#if NET_2_1 && !MONOTOUCH
+#if MOONLIGHT
                                // we don't control the content of 'info.FileName' so we want to make sure we keep to ourselves
                                filename = Path.GetFullPath (filename);
                                if (!filename.StartsWith (location))
@@ -362,16 +364,6 @@ namespace System.Reflection {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern Type InternalGetType (Module module, String name, Boolean throwOnError, Boolean ignoreCase);
 
-               public Type GetType (string name, bool throwOnError, bool ignoreCase)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException (name);
-                       if (name.Length == 0)
-                       throw new ArgumentException ("name", "Name cannot be empty");
-
-                       return InternalGetType (null, name, throwOnError, ignoreCase);
-               }
-
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern static void InternalGetAssemblyName (string assemblyFile, AssemblyName aname);
 
@@ -428,22 +420,12 @@ namespace System.Reflection {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public static extern Assembly GetEntryAssembly();
 
-               public Assembly GetSatelliteAssembly (CultureInfo culture)
-               {
-                       return GetSatelliteAssembly (culture, null, true);
-               }
-
-               public Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
-               {
-                       return GetSatelliteAssembly (culture, version, true);
-               }
-
                internal Assembly GetSatelliteAssemblyNoThrow (CultureInfo culture, Version version)
                {
                        return GetSatelliteAssembly (culture, version, false);
                }
 
-               private Assembly GetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnError)
+               internal Assembly GetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnError)
                {
                        if (culture == null)
                                throw new ArgumentException ("culture");
@@ -468,7 +450,7 @@ namespace System.Reflection {
                        // Try the assembly directory
                        string location = Path.GetDirectoryName (Location);
                        string fullName = Path.Combine (location, Path.Combine (culture.Name, aname.Name + ".dll"));
-#if NET_2_1 && !MONOTOUCH
+#if MOONLIGHT
                        // it's unlikely that culture.Name or aname.Name could contain stuff like ".." but...
                        fullName = Path.GetFullPath (fullName);
                        if (!fullName.StartsWith (location)) {
@@ -491,6 +473,9 @@ namespace System.Reflection {
                        return LoadFrom (assemblyFile, false);
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
                {
                        Assembly a = LoadFrom (assemblyFile, false);
@@ -503,6 +488,9 @@ namespace System.Reflection {
                        return a;
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                [MonoTODO("This overload is not currently implemented")]
                // FIXME: What are we missing?
                public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
@@ -514,6 +502,9 @@ namespace System.Reflection {
                        throw new NotImplementedException ();
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly LoadFile (String path, Evidence securityEvidence)
                {
                        if (path == null)
@@ -533,7 +524,10 @@ namespace System.Reflection {
                {
                        return AppDomain.CurrentDomain.Load (assemblyString);
                }
-               
+
+#if NET_4_0
+               [Obsolete]
+#endif         
                public static Assembly Load (String assemblyString, Evidence assemblySecurity)
                {
                        return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
@@ -544,6 +538,9 @@ namespace System.Reflection {
                        return AppDomain.CurrentDomain.Load (assemblyRef);
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
                {
                        return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
@@ -559,6 +556,9 @@ namespace System.Reflection {
                        return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
                                             Evidence securityEvidence)
                {
@@ -583,6 +583,9 @@ namespace System.Reflection {
                        return LoadFrom (assemblyFile, true);
                }
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly LoadWithPartialName (string partialName)
                {
                        return LoadWithPartialName (partialName, null);
@@ -595,7 +598,11 @@ namespace System.Reflection {
                }
 
                [MonoTODO ("Not implemented")]
-               public Module LoadModule (string moduleName, byte [] rawModule, byte [] rawSymbolStore)
+               public
+#if NET_4_0
+               virtual
+#endif
+               Module LoadModule (string moduleName, byte [] rawModule, byte [] rawSymbolStore)
                {
                        throw new NotImplementedException ();
                }
@@ -603,6 +610,9 @@ namespace System.Reflection {
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private static extern Assembly load_with_partial_name (string name, Evidence e);
 
+#if NET_4_0
+               [Obsolete]
+#endif
                public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
                {
                        return LoadWithPartialName (partialName, securityEvidence, true);
@@ -645,7 +655,11 @@ namespace System.Reflection {
                        }
                }
 
-               public Object CreateInstance (String typeName, Boolean ignoreCase,
+               public
+#if NET_4_0
+               virtual
+#endif
+               Object CreateInstance (String typeName, Boolean ignoreCase,
                                              BindingFlags bindingAttr, Binder binder,
                                              Object[] args, CultureInfo culture,
                                              Object[] activationAttributes)
@@ -666,49 +680,14 @@ namespace System.Reflection {
                        return GetLoadedModules (false);
                }
 
-               // FIXME: Currently, the two sets of modules are equal
-               public Module[] GetLoadedModules (bool getResourceModules)
-               {
-                       return GetModules (getResourceModules);
-               }
-
                public Module[] GetModules ()
                {
                        return GetModules (false);
                }
 
-               public Module GetModule (String name)
-               {
-                       if (name == null)
-                               throw new ArgumentNullException ("name");
-                       if (name.Length == 0)
-                               throw new ArgumentException ("Name can't be empty");
-
-                       Module[] modules = GetModules (true);
-                       foreach (Module module in modules) {
-                               if (module.ScopeName == name)
-                                       return module;
-                       }
-
-                       return null;
-               }
-
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal virtual extern Module[] GetModulesInternal ();
 
-               public Module[] GetModules (bool getResourceModules) {
-                       Module[] modules = GetModulesInternal ();
-
-                       if (!getResourceModules) {
-                               ArrayList result = new ArrayList (modules.Length);
-                               foreach (Module m in modules)
-                                       if (!m.IsResource ())
-                                               result.Add (m);
-                               return (Module[])result.ToArray (typeof (Module));
-                       }
-                       else
-                               return modules;
-               }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal extern string[] GetNamespaces ();
@@ -723,7 +702,7 @@ namespace System.Reflection {
                public extern static Assembly GetCallingAssembly ();
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern AssemblyName[] GetReferencedAssemblies ();
+               internal static extern AssemblyName[] GetReferencedAssemblies (Assembly module);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private extern bool GetManifestResourceInfoInternal (String name, ManifestResourceInfo info);
@@ -766,16 +745,14 @@ namespace System.Reflection {
 
                [MonoTODO ("Currently it always returns zero")]
                [ComVisible (false)]
-               public long HostContext {
+               public
+#if NET_4_0
+               virtual
+#endif
+               long HostContext {
                        get { return 0; }
                }
 
-               [ComVisible (false)]
-               public Module ManifestModule {
-                       get {
-                               return GetManifestModule ();
-                       }
-               }
 
                internal virtual Module GetManifestModule () {
                        return GetManifestModuleInternal ();
@@ -802,7 +779,13 @@ namespace System.Reflection {
                        return other._mono_assembly == _mono_assembly;
                }
                
-#if !NET_2_1 || MONOTOUCH
+#if NET_4_0
+               public virtual IList<CustomAttributeData> GetCustomAttributesData () {
+                       return CustomAttributeData.GetCustomAttributes (this);
+               }
+#endif
+
+#if !MOONLIGHT
                // Code Access Security
 
                internal void Resolve () 
@@ -884,6 +867,56 @@ namespace System.Reflection {
                        }
                }
 #endif
+
+#if NET_4_0
+               static Exception CreateNIE ()
+               {
+                       return new NotSupportedException ("Derived classes must implement it");
+               }
+
+               public virtual Type GetType (string name, bool throwOnError, bool ignoreCase)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Module GetModule (String name)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual AssemblyName[] GetReferencedAssemblies ()
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Module[] GetModules (bool getResourceModules)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Module[] GetLoadedModules (bool getResourceModules)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Assembly GetSatelliteAssembly (CultureInfo culture)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
+               {
+                       throw CreateNIE ();
+               }
+
+               public virtual Module ManifestModule {
+                       get { throw CreateNIE (); }
+               }
+
+               public virtual bool GlobalAssemblyCache {
+                       get { throw CreateNIE (); }
+               }
+#endif
        }
 }