mscorlib(4.0.0.0) API with additions
XmlSerializationGeneratedCode.cs
1 using System.Reflection;
2 using System.Threading;
3 
5 {
7  public abstract class XmlSerializationGeneratedCode
8  {
9  private TempAssembly tempAssembly;
10 
11  private int threadCode;
12 
13  private ResolveEventHandler assemblyResolver;
14 
15  internal void Init(TempAssembly tempAssembly)
16  {
17  this.tempAssembly = tempAssembly;
18  if (tempAssembly != null && tempAssembly.NeedAssembyResolve)
19  {
20  threadCode = Thread.CurrentThread.GetHashCode();
21  assemblyResolver = OnAssemblyResolve;
22  AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver;
23  }
24  }
25 
26  internal void Dispose()
27  {
28  if (assemblyResolver != null)
29  {
30  AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolver;
31  }
32  assemblyResolver = null;
33  }
34 
35  internal Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
36  {
37  if (tempAssembly != null && Thread.CurrentThread.GetHashCode() == threadCode)
38  {
39  return tempAssembly.GetReferencedAssembly(args.Name);
40  }
41  return null;
42  }
43  }
44 }
static Thread CurrentThread
Gets the currently running thread.
Definition: Thread.cs:134
Definition: __Canon.cs:3
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Definition: AppDomain.cs:274
Represents an application domain, which is an isolated environment where applications execute....
Definition: AppDomain.cs:33
override int GetHashCode()
Returns a hash code for the current thread.
Definition: Thread.cs:460
string Name
Gets the name of the item to resolve.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
Provides data for loader resolution events, such as the E:System.AppDomain.TypeResolve,...
An abstract class that is the base class for T:System.Xml.Serialization.XmlSerializationReader and T:...
delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args)
Represents a method that handles the E:System.AppDomain.TypeResolve, E:System.AppDomain....
ResolveEventHandler AssemblyResolve
Occurs when the resolution of an assembly fails.
Definition: AppDomain.cs:638
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18