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
38 // TODO: Maybe we can lazily do this, as loaded_assemblies
39 // will not be used all the time, we can just compute this on
42 foreach (Assembly a in getDefaultAssemblies ())
43 loaded_assemblies [a.FullName] = a;
46 public AppDomainSetup SetupInformation {
53 public string BaseDirectory {
56 return adsetup.ApplicationBase;
60 public string RelativeSearchPath {
63 return adsetup.PrivateBinPath;
67 public string DynamicDirectory {
70 // fixme: dont know what to return here
75 public string FriendlyName {
82 public Evidence Evidence {
90 public static AppDomain CreateDomain (string friendlyName)
92 return CreateDomain (friendlyName, new Evidence (), new AppDomainSetup ());
95 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo)
97 return CreateDomain (friendlyName, securityInfo, new AppDomainSetup ());
100 public static AppDomain CreateDomain (string friendlyName,
101 Evidence securityInfo,
104 if (friendlyName == null || securityInfo == null || info == null)
105 throw new System.ArgumentNullException();
107 AppDomain ad = new AppDomain ();
109 ad.friendly_name = friendlyName;
110 ad.evidence = securityInfo;
116 public static AppDomain CreateDomain (string friendlyName, Evidence securityInfo,
117 string appBasePath, string appRelativeSearchPath,
118 bool shadowCopyFiles)
120 AppDomainSetup info = new AppDomainSetup ();
122 info.ApplicationBase = appBasePath;
123 info.PrivateBinPath = appRelativeSearchPath;
126 info.ShadowCopyFiles = "true";
128 info.ShadowCopyFiles = "false";
130 return CreateDomain (friendlyName, securityInfo, info);
133 [MethodImplAttribute (MethodImplOptions.InternalCall)]
134 public static extern Assembly LoadFrom (String assemblyFile, Evidence securityEvidence);
136 [MethodImplAttribute (MethodImplOptions.InternalCall)]
137 private static extern AppDomain getCurDomain ();
139 public static AppDomain CurrentDomain
142 return getCurDomain ();
146 public AssemblyBuilder DefineDynamicAssembly (AssemblyName name,
147 AssemblyBuilderAccess access)
149 AssemblyBuilder ab = new AssemblyBuilder (name, access);
153 public Assembly Load (AssemblyName assemblyRef)
155 return Load (assemblyRef, new Evidence ());
158 public Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
162 if ((res = (Assembly)loaded_assemblies [assemblyRef]) != null)
165 // fixme: we should pass the whole assemblyRef instead of the name,
166 // and maybe also the adsetup
167 res = LoadFrom (assemblyRef.Name, assemblySecurity);
169 loaded_assemblies [assemblyRef] = res;
174 public Assembly Load (string assemblyString)
176 AssemblyName an = new AssemblyName ();
177 an.Name = assemblyString;
179 return Load (an, new Evidence ());
182 public Assembly Load (string assemblyString, Evidence assemblySecurity)
184 AssemblyName an = new AssemblyName ();
185 an.Name = assemblyString;
187 return Load (an, assemblySecurity);
190 public Assembly Load (byte[] rawAssembly)
192 return Load (rawAssembly, null, new Evidence ());
195 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore)
197 return Load (rawAssembly, rawSymbolStore, new Evidence ());
200 public Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
202 throw new NotImplementedException ();
206 // This returns a list of the assemblies that were loaded in behalf
209 [MethodImplAttribute(MethodImplOptions.InternalCall)]
210 static private extern Assembly [] getDefaultAssemblies ();
212 public Assembly[] GetAssemblies ()
214 int x = loaded_assemblies.Count;
215 Assembly[] res = new Assembly [loaded_assemblies.Count];
218 foreach (DictionaryEntry de in loaded_assemblies)
219 res [i++] = (Assembly) de.Value;
224 // fixme: how does marshalling work ?
225 public object GetData (string name)
229 return adsetup.ApplicationBase;
230 case "APP_CONFIG_FILE":
231 return adsetup.ConfigurationFile;
233 return adsetup.DynamicBase;
235 return adsetup.ApplicationName;
237 return adsetup.CachePath;
238 case "PRIVATE_BINPATH":
239 return adsetup.PrivateBinPath;
240 case "BINPATH_PROBE_ONLY":
241 return adsetup.PrivateBinPathProbe;
242 case "SHADOW_COPY_DIRS":
243 return adsetup.ShadowCopyDirectories;
244 case "FORCE_CACHE_INSTALL":
245 return adsetup.ShadowCopyFiles;
248 return data_hash [name];
251 // fixme: how does marshalling work ?
252 public void SetData (string name, object data)
254 // LAMESPEC: why can't we set adsetup properties ??
256 data_hash [name] = data;