2005-02-24 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 24 Feb 2005 08:43:28 +0000 (08:43 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Thu, 24 Feb 2005 08:43:28 +0000 (08:43 -0000)
* Assembly.cs: LoadFrom: Change signature to support reflection only
methods; ReflectionOnlyLoad, ReflectionOnlyLoadFrom 2.0 methods
implemented; InvalidOperationException's re-thrown by CreateInstance.
Also ReflectionOnly 2.0 property added.

* MonoMethod.cs: InvalidOperationException's are re-thrown when calling
Invoke method on reflection only assemblies.

svn path=/trunk/mcs/; revision=41142

mcs/class/corlib/System.Reflection/Assembly.cs
mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MonoMethod.cs

index ce11c4a924eec7994b2385f3852e61b51c1a51d3..b11af03723e80ab68a7d083ce083f86f16b4de08 100644 (file)
@@ -360,11 +360,16 @@ namespace System.Reflection {
                }
                
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static Assembly LoadFrom (String assemblyFile);
+               private extern static Assembly LoadFrom (String assemblyFile, bool refonly);
+
+               public static Assembly LoadFrom (String assemblyFile)
+               {
+                       return LoadFrom (assemblyFile, false);
+               }
 
                public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
                {
-                       Assembly a = LoadFrom (assemblyFile);
+                       Assembly a = LoadFrom (assemblyFile, false);
                        if ((a != null) && (securityEvidence != null)) {
                                // merge evidence (i.e. replace defaults with provided evidences)
                                a.Evidence.Merge (securityEvidence);
@@ -436,20 +441,22 @@ namespace System.Reflection {
                }
 
 #if NET_2_0
-               [MonoTODO]
                public static Assembly ReflectionOnlyLoad (byte[] rawAssembly)
                {
-                       throw new NotImplementedException ();
+                       return AppDomain.CurrentDomain.Load (rawAssembly, null, null, true);
                }
 
-               [MonoTODO]
-               public static Assembly ReflectionOnlyLoad (string assemblyString) {
-                       throw new NotImplementedException ();
+               public static Assembly ReflectionOnlyLoad (string assemblyName) 
+               {
+                       return AppDomain.CurrentDomain.Load (assemblyName, null, true);
                }
 
-               [MonoTODO]
-               public static Assembly ReflectionOnlyLoadFrom (string assemblyFile) {
-                       throw new NotImplementedException ();
+               public static Assembly ReflectionOnlyLoadFrom (string assemblyFile) 
+               {
+                       if (assemblyFile == null)
+                               throw new ArgumentNullException ("assemblyFile");
+                       
+                       return LoadFrom (assemblyFile, true);
                }
 #endif
 
@@ -524,7 +531,11 @@ namespace System.Reflection {
                        if (t == null)
                                return null;
 
-                       return Activator.CreateInstance (t);
+                       try {
+                               return Activator.CreateInstance (t);
+                       } catch (InvalidOperationException) {
+                               throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
+                       }
                }
 
                public Object CreateInstance (String typeName, Boolean ignoreCase,
@@ -536,7 +547,11 @@ namespace System.Reflection {
                        if (t == null)
                                return null;
 
-                       return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
+                       try {
+                               return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
+                       } catch (InvalidOperationException) {
+                               throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
+                       }
                }
 
                public Module[] GetLoadedModules ()
@@ -704,10 +719,10 @@ namespace System.Reflection {
                        }
                }
 
-               [MonoTODO ("see ReflectionOnlyLoad")]
                [ComVisible (false)]
-               public virtual bool ReflectionOnly {
-                       get { return false; }
+               public virtual extern bool ReflectionOnly {
+                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
+                       get;
                }
 #endif
 
index 4fe6086c579547836cd5f79c0ff44ff13f8094a4..ce481b2cceb25741be9263561e1ee6cb5290d947 100644 (file)
@@ -1,3 +1,13 @@
+2005-02-24  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * Assembly.cs: LoadFrom: Change signature to support reflection only
+       methods; ReflectionOnlyLoad, ReflectionOnlyLoadFrom 2.0 methods
+       implemented; InvalidOperationException's re-thrown by CreateInstance.
+       Also ReflectionOnly 2.0 property added.
+
+       * MonoMethod.cs: InvalidOperationException's are re-thrown when calling 
+       Invoke method on reflection only assemblies.
+       
 2005-02-22  Raja R Harinath  <rharinath@novell.com>
 
        * FieldInfo.cs (GetFieldOffset): Make 'virtual' rather than
index 28382800572feb8c88fda1192582fa60ecbbcdbe..d25cbb0148934be7ce0fc031108ce7ae8d98cf04 100644 (file)
@@ -118,6 +118,8 @@ namespace System.Reflection {
                                throw new ArgumentException ("parameters");
                        try {
                                return InternalInvoke (obj, parameters);
+                       } catch (InvalidOperationException) {
+                               throw;
                        } catch (TargetException) {
                                throw;
                        } catch (Exception e) {
@@ -316,6 +318,8 @@ namespace System.Reflection {
                                throw new ArgumentException ("parameters");
                        try {
                                return InternalInvoke (obj, parameters);
+                       } catch (InvalidOperationException) {
+                               throw;
                        } catch (TargetException) {
                                throw;
                        } catch (Exception e) {