6 // Paolo Molaro (lupus@ximian.com)
7 // Dietmar Maurer (dietmar@ximian.com)
8 // Miguel de Icaza (miguel@ximian.com)
10 // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
14 using System.Collections;
15 using System.Reflection;
16 using System.Reflection.Emit;
17 using System.Runtime.CompilerServices;
18 using System.Security.Policy;
22 public sealed class AppDomain /* : MarshalByRefObject , _AppDomain, IEvidenceFactory */ {
24 private Hashtable loaded_assemblies = new Hashtable ();
25 private Hashtable data_hash = new Hashtable ();
26 private AppDomainSetup adsetup;
27 private string friendly_name;
28 private Evidence evidence;
33 // Prime the loaded assemblies with the assemblies that were loaded
34 // by the runtime in our behalf
36 foreach (Assembly a in getDefaultAssemblies ())
37 loaded_assemblies [a.FullName] = a;
40 public AppDomainSetup SetupInformation {
47 public string BaseDirectory {
50 return adsetup.ApplicationBase;
54 public string RelativeSearchPath {
57 return adsetup.PrivateBinPath;
61 public string DynamicDirectory {
64 // fixme: dont know what to return here
69 public string FriendlyName {
76 public Evidence Evidence {
84 public static AppDomain CreateDomain (string friendlyName)
86 return CreateDomain (friendlyName, new Evidence (), new AppDomainSetup ());
89 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
91 return CreateDomain (friendlyName, securityInfo, new AppDomainSetup ());
94 public static AppDomain CreateDomain (string friendlyName,
95 Evidence securityInfo,
98 if (friendlyName == null || securityInfo == null || info == null)
99 throw new System.ArgumentNullException();
101 AppDomain ad = new AppDomain ();
103 ad.friendly_name = friendlyName;
104 ad.evidence = securityInfo;
110 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,
111 string appBasePath, string appRelativeSearchPath,
112 bool shadowCopyFiles)
114 AppDomainSetup info = new AppDomainSetup ();
116 info.ApplicationBase = appBasePath;
117 info.PrivateBinPath = appRelativeSearchPath;
120 info.ShadowCopyFiles = "true";
122 info.ShadowCopyFiles = "false";
124 return CreateDomain (friendlyName, securityInfo, info);
127 [MethodImplAttribute (MethodImplOptions.InternalCall)]
128 public static extern Assembly LoadFrom (String assemblyFile, Evidence securityEvidence);
130 [MethodImplAttribute (MethodImplOptions.InternalCall)]
131 private static extern AppDomain getCurDomain ();
133 public static AppDomain CurrentDomain
136 return getCurDomain ();
140 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name,
141 AssemblyBuilderAccess access)
143 AssemblyBuilder ab = new AssemblyBuilder (name, access);
147 public Assembly Load (AssemblyName assemblyRef)
149 return Load (assemblyRef, new Evidence ());
152 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
156 if ((res = (Assembly)loaded_assemblies [assemblyRef]) != null)
159 // fixme: we should pass the whole assemblyRef instead of the name,
160 // and maybe also the adsetup
161 res = LoadFrom (assemblyRef.Name, assemblySecurity);
163 loaded_assemblies [assemblyRef] = res;
168 public Assembly Load (string assemblyString)
170 AssemblyName an = new AssemblyName ();
171 an.Name = assemblyString;
173 return Load (an, new Evidence ());
176 public Assembly Load (string assemblyString, Evidence assemblySecurity)
178 AssemblyName an = new AssemblyName ();
179 an.Name = assemblyString;
181 return Load (an, assemblySecurity);
184 public Assembly Load (byte[] rawAssembly)
186 return Load (rawAssembly, null, new Evidence ());
189 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
191 return Load (rawAssembly, rawSymbolStore, new Evidence ());
194 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
196 throw new NotImplementedException ();
200 // This returns a list of the assemblies that were loaded in behalf
203 [MethodImplAttribute(MethodImplOptions.InternalCall)]
204 static private extern Assembly [] getDefaultAssemblies ();
206 public Assembly[] GetAssemblies ()
208 int x = loaded_assemblies.Count;
209 Assembly[] res = new Assembly [loaded_assemblies.Count];
212 foreach (DictionaryEntry de in loaded_assemblies)
213 res [i++] = (Assembly) de.Value;
218 // fixme: how does marshalling work ?
219 public object GetData (string name)
223 return adsetup.ApplicationBase;
224 case "APP_CONFIG_FILE":
225 return adsetup.ConfigurationFile;
227 return adsetup.DynamicBase;
229 return adsetup.ApplicationName;
231 return adsetup.CachePath;
232 case "PRIVATE_BINPATH":
233 return adsetup.PrivateBinPath;
234 case "BINPATH_PROBE_ONLY":
235 return adsetup.PrivateBinPathProbe;
236 case "SHADOW_COPY_DIRS":
237 return adsetup.ShadowCopyDirectories;
238 case "FORCE_CACHE_INSTALL":
239 return adsetup.ShadowCopyFiles;
242 return data_hash [name];
245 // fixme: how does marshalling work ?
246 public void SetData (string name, object data)
248 // LAMESPEC: why can't we set adsetup properties ??
250 data_hash [name] = data;