2002-08-21 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System / AppDomain.cs
index ebb4ba95bf2aca3aa8cd02f38db4d8e3ab3bf075..1dc498e42b160c30cd820e1dac390edd77828549 100755 (executable)
@@ -5,6 +5,7 @@
 //   Paolo Molaro (lupus@ximian.com)
 //   Dietmar Maurer (dietmar@ximian.com)
 //   Miguel de Icaza (miguel@ximian.com)
+//   Gonzalo Paniagua (gonzalo@ximian.com)
 //
 // (C) 2001, 2002 Ximian, Inc.  http://www.ximian.com
 //
@@ -27,9 +28,11 @@ namespace System {
                IntPtr _mono_app_domain;
 
                // Evidence evidence;
+
+               private AppDomain () {}
                
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern AppDomainSetup getSetup ();
+               private extern AppDomainSetup getSetup ();
 
                public AppDomainSetup SetupInformation {
 
@@ -70,7 +73,7 @@ namespace System {
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern string getFriendlyName ();
+               private extern string getFriendlyName ();
 
                public string FriendlyName {
 
@@ -97,16 +100,19 @@ namespace System {
                        }
                }
 
+               [MonoTODO]
                public void AppendPrivatePath (string path)
                {
                        throw new NotImplementedException ();
                }
                
+               [MonoTODO]
                public void ClearPrivatePath ()
                {
                        throw new NotImplementedException ();
                }
                
+               [MonoTODO]
                public void ClearShadowCopyPath ()
                {
                        throw new NotImplementedException ();
@@ -114,15 +120,19 @@ namespace System {
 
                public ObjectHandle CreateInstance (string assemblyName, string typeName)
                {
-                       return CreateInstance (assemblyName, typeName, false, 0,
-                                              null, null, null, null, null);
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstance (assemblyName, typeName);
                }
 
                public ObjectHandle CreateInstance (string assemblyName, string typeName,
                                                    object[] activationAttributes)
                {
-                       return CreateInstance (assemblyName, typeName, false, 0,
-                                              null, null, null, activationAttributes, null);
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstance (assemblyName, typeName, activationAttributes);
                }
                
                public ObjectHandle CreateInstance (string assemblyName,
@@ -133,22 +143,73 @@ namespace System {
                                                    object[] args,
                                                    CultureInfo culture,
                                                    object[] activationAttributes,
-                                                   Evidence securityAttribtutes)
+                                                   Evidence securityAttributes)
                {
-                       throw new NotImplementedException ();
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstance (assemblyName,
+                                                        typeName,
+                                                        ignoreCase,
+                                                        bindingAttr,
+                                                        binder,
+                                                        args,
+                                                        culture,
+                                                        activationAttributes,
+                                                        securityAttributes);
+               }
+
+               public object CreateInstanceAndUnwrap (string assemblyName, string typeName)
+               {
+                       ObjectHandle oh = CreateInstance (assemblyName, typeName);
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+               
+               public object CreateInstanceAndUnwrap (string assemblyName,
+                                                      string typeName,
+                                                      object [] activationAttributes)
+               {
+                       ObjectHandle oh = CreateInstance (assemblyName, typeName, activationAttributes);
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+
+               public object CreateInstanceAndUnwrap (string assemblyName,
+                                                      string typeName,
+                                                      bool ignoreCase,
+                                                      BindingFlags bindingAttr,
+                                                      Binder binder,
+                                                      object[] args,
+                                                      CultureInfo culture,
+                                                      object[] activationAttributes,
+                                                      Evidence securityAttributes)
+               {
+                       ObjectHandle oh = CreateInstance (assemblyName,
+                                                         typeName,
+                                                         ignoreCase,
+                                                         bindingAttr,
+                                                         binder,
+                                                         args,
+                                                         culture,
+                                                         activationAttributes,
+                                                         securityAttributes);
+                       return (oh != null) ? oh.Unwrap () : null;
                }
 
                public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName)
                {
-                       return CreateInstanceFrom (assemblyName, typeName, false, 0,
-                                                  null, null, null, null, null);
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstanceFrom (assemblyName, typeName);
                }
                
                public ObjectHandle CreateInstanceFrom (string assemblyName, string typeName,
                                                        object[] activationAttributes)
                {
-                       return CreateInstanceFrom (assemblyName, typeName, false, 0,
-                                                  null, null, null, activationAttributes, null);
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstanceFrom (assemblyName, typeName, activationAttributes);
                }
                
                public ObjectHandle CreateInstanceFrom (string assemblyName,
@@ -159,9 +220,56 @@ namespace System {
                                                        object[] args,
                                                        CultureInfo culture,
                                                        object[] activationAttributes,
-                                                       Evidence securityAttribtutes)
+                                                       Evidence securityAttributes)
                {
-                       throw new NotImplementedException ();                   
+                       if (assemblyName == null)
+                               throw new ArgumentNullException ("assemblyName");
+
+                       return Activator.CreateInstanceFrom (assemblyName,
+                                                            typeName,
+                                                            ignoreCase,
+                                                            bindingAttr,
+                                                            binder,
+                                                            args,
+                                                            culture,
+                                                            activationAttributes,
+                                                            securityAttributes);
+               }
+
+               public object CreateInstanceFromAndUnwrap (string assemblyName, string typeName)
+               {
+                       ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName);
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+               
+               public object CreateInstanceFromAndUnwrap (string assemblyName,
+                                                          string typeName,
+                                                          object [] activationAttributes)
+               {
+                       ObjectHandle oh = CreateInstanceFrom (assemblyName, typeName, activationAttributes);
+                       return (oh != null) ? oh.Unwrap () : null;
+               }
+
+               public object CreateInstanceFromAndUnwrap (string assemblyName,
+                                                          string typeName,
+                                                          bool ignoreCase,
+                                                          BindingFlags bindingAttr,
+                                                          Binder binder,
+                                                          object[] args,
+                                                          CultureInfo culture,
+                                                          object[] activationAttributes,
+                                                          Evidence securityAttributes)
+               {
+                       ObjectHandle oh = CreateInstanceFrom (assemblyName,
+                                                             typeName,
+                                                             ignoreCase,
+                                                             bindingAttr,
+                                                             binder,
+                                                             args,
+                                                             culture,
+                                                             activationAttributes,
+                                                             securityAttributes);
+                       return (oh != null) ? oh.Unwrap () : null;
                }
 
                public AssemblyBuilder DefineDynamicAssembly (AssemblyName name,
@@ -256,11 +364,12 @@ namespace System {
                {
                        // FIXME: examine all other parameters
                        
-                       AssemblyBuilder ab = new AssemblyBuilder (name, access);
+                       AssemblyBuilder ab = new AssemblyBuilder (name, dir, access);
                        return ab;
                }
 
 
+               [MonoTODO]
                public void DoCallBack (CrossAppDomainDelegate theDelegate)
                {
                        throw new NotImplementedException ();
@@ -290,28 +399,22 @@ namespace System {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern Assembly [] GetAssemblies ();
 
-               public object GetDate (string name)
-               {
-                       throw new NotImplementedException ();                   
-               }
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern object GetData (string name);
                
                public override int GetHashCode ()
                {
                        return (int)_mono_app_domain;
                }
 
-               public object GetLifetimeService ()
-               {
-                       throw new NotImplementedException ();                   
-               }
-
-               public object InitializeLifetimeService ()
+               [MonoTODO]
+               public override object InitializeLifetimeService ()
                {
                        throw new NotImplementedException ();                   
                }
        
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern Assembly LoadAssembly (AssemblyName assemblyRef, Evidence securityEvidence);
+               private extern Assembly LoadAssembly (AssemblyName assemblyRef, Evidence securityEvidence);
 
                public Assembly Load (AssemblyName assemblyRef)
                {
@@ -349,11 +452,13 @@ namespace System {
                        return Load (rawAssembly, rawSymbolStore, new Evidence ());
                }
 
+               [MonoTODO]
                public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
                {
                        throw new NotImplementedException ();
                }
                        
+               [MonoTODO]
                public void SetAppDomainPolicy (PolicyLevel domainPolicy)
                {
                        throw new NotImplementedException ();
@@ -364,16 +469,19 @@ namespace System {
                        SetupInformation.CachePath = s;
                }
                
+               [MonoTODO]
                public void SetPrincipalPolicy (PrincipalPolicy policy)
                {
                        throw new NotImplementedException ();
                }
                
+               [MonoTODO]
                public void SetShadowCopyPath (string s)
                {
                        throw new NotImplementedException ();
                }
                
+               [MonoTODO]
                public void SetThreadPrincipal (IPrincipal principal)
                {
                        throw new NotImplementedException ();
@@ -396,8 +504,12 @@ namespace System {
                                                      Evidence securityInfo,
                                                      AppDomainSetup info)
                {
-                       if (friendlyName == null || securityInfo == null || info == null)
-                               throw new System.ArgumentNullException();
+                       //TODO: treat securityInfo (can be null)
+                       if (friendlyName == null)
+                               throw new System.ArgumentNullException ("friendlyName");
+
+                       if (info == null)
+                               throw new System.ArgumentNullException ("info");
 
                        AppDomain ad = createDomain (friendlyName, info);
 
@@ -427,17 +539,19 @@ namespace System {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public static extern void Unload (AppDomain domain);
                
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               public extern object GetData ();
-
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern void SetData (string name, object data);
 
+               [MonoTODO]
                public static int GetCurrentThreadId ()
                {
                        throw new NotImplementedException ();
                }
 
+               public override string ToString () {
+                       return getFriendlyName ();
+               }
+
 
                public event AssemblyLoadEventHandler AssemblyLoad;