C# Class Microsoft.Cci.MetadataReaderHost

A base class for an object provided by the application hosting the metadata reader. The object allows the host application to control how assembly references are unified, where files are found and so on. The object also controls the lifetime of things such as memory mapped files and blocks of unmanaged memory. Be sure to call Dispose on the object when it is no longer needed and the associated locks and/or memory must be released immediately.
Inheritance: MetadataHostEnvironment, IMetadataReaderHost, IDisposable
Show file Open project: visualmutator/visualmutator Class Usage Examples

Protected Properties

Property Type Description
disposableObjectAllocatedByThisHost List

Public Methods

Method Description
Dispose ( ) : void

Calls IDiposable.Dispose on any disposable objects allocated by this host environment.

GuessUnderlyingTypeSizeOfUnresolvableReferenceToEnum ( ITypeReference reference ) : byte

Returns a guess of the size of the underlying type of the given type reference to an enum type, which is assumed to be unresolvable because it is defined an assembly that is not loaded into this host. Successive calls to the method will cycle through these values with a periodicity determined by the number of types in the game and the successful guesses made in earlier games.

OpenBinaryDocument ( IBinaryDocument sourceDocument ) : IBinaryDocumentMemoryBlock

Open the binary document as a memory block in host dependent fashion. IMPORTANT: The lifetime of the memory block is the same as the lifetime of this host object. Be sure to call Dispose on the host object when it is no longer needed, otherwise files may stay locked, or resources such as large blocks of memory may remain allocated until the host's finalizer method runs.

When overridding this method, be sure to add any disposable objects to this.disposableObjectAllocatedByThisHost.

OpenBinaryDocument ( IBinaryDocument parentSourceDocument, string childDocumentName ) : IBinaryDocumentMemoryBlock

Open the child binary document within the context of parent source document.as a memory block in host dependent fashion For example: in multimodule assemblies the main module will be parentSourceDocument, where as other modules will be child documents. IMPORTANT: The lifetime of the memory block is the same as the lifetime of this host object. Be sure to call Dispose on the host object when it is no longer needed, otherwise files may stay locked, or resources such as large blocks of memory may remain allocated until the host's finalizer method runs.

When overridding this method, be sure to add any disposable objects to this.disposableObjectAllocatedByThisHost.

Redirect ( IUnit referringUnit, IEnumerable assemblyReferences ) : IEnumerable

Provides the host with an opportunity to add, remove or substitute assembly references in the given list. This avoids the cost of rewriting the entire unit in order to make such changes.

Redirect ( IUnit referringUnit, INamedTypeReference typeReference ) : INamedTypeReference

Provides the host with an opportunity to substitute one named type reference for another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.

ResolvingAssemblyReference ( IUnit referringUnit, Microsoft.Cci.AssemblyIdentity referencedAssembly ) : void

This method is called when the assembly reference is being resolved and its not already loaded by the Read/Write host.

ResolvingModuleReference ( IUnit referringUnit, Microsoft.Cci.ModuleIdentity referencedModule ) : void

This method is called when the module reference is being resolved and its not already loaded by the Read/Write host.

Rewrite ( IUnit containingUnit, ICustomAttribute customAttribute ) : ICustomAttribute

Provides the host with an opportunity to substitute a custom attribute with another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.

Rewrite ( IUnit containingUnit, IMethodDefinition methodDefinition ) : IMethodDefinition

Provides the host with an opportunity to substitute one method definition for another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.

StartGuessingGame ( ) : void

Called by the metadata reader when it is about to start parsing a custom attribute blob.

TryNextPermutation ( ) : bool

Called by the metadata reader when it has unsucessfully tried to parse a custom attribute blob and it now needs to try a new permutation. Returns false if no more perumations are possible.

WinGuessingGame ( ) : void

Called by the metadata reader when it has successfully parsed a custom attribute blob.

Protected Methods

Method Description
MetadataReaderHost ( INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable searchPaths, bool searchInGAC ) : System

Allocates an object that provides an abstraction over the application hosting compilers based on this framework. Remember to call the Dispose method when the resulting object is no longer needed.

Private Methods

Method Description
Close ( ) : void

Calls IDiposable.Dispose on any disposable objects allocated by this host environment.

Method Details

Dispose() public method

Calls IDiposable.Dispose on any disposable objects allocated by this host environment.
public Dispose ( ) : void
return void

GuessUnderlyingTypeSizeOfUnresolvableReferenceToEnum() public method

Returns a guess of the size of the underlying type of the given type reference to an enum type, which is assumed to be unresolvable because it is defined an assembly that is not loaded into this host. Successive calls to the method will cycle through these values with a periodicity determined by the number of types in the game and the successful guesses made in earlier games.
public GuessUnderlyingTypeSizeOfUnresolvableReferenceToEnum ( ITypeReference reference ) : byte
reference ITypeReference A type reference that cannot be resolved.
return byte

MetadataReaderHost() protected method

Allocates an object that provides an abstraction over the application hosting compilers based on this framework. Remember to call the Dispose method when the resulting object is no longer needed.
protected MetadataReaderHost ( INameTable nameTable, IInternFactory factory, byte pointerSize, IEnumerable searchPaths, bool searchInGAC ) : System
nameTable INameTable /// A collection of IName instances that represent names that are commonly used during compilation. /// This is a provided as a parameter to the host environment in order to allow more than one host /// environment to co-exist while agreeing on how to map strings to IName instances. ///
factory IInternFactory /// The intern factory to use when generating keys. When comparing two or more assemblies using /// TypeHelper, MemberHelper, etc. it is necessary to make the hosts use the same intern factory. ///
pointerSize byte The size of a pointer on the runtime that is the target of the metadata units to be loaded /// into this metadta host. This parameter only matters if the host application wants to work out what the exact layout /// of a struct will be on the target runtime. The framework uses this value in methods such as TypeHelper.SizeOfType and /// TypeHelper.TypeAlignment. If the host application does not care about the pointer size it can provide 0 as the value /// of this parameter. In that case, the first reference to IMetadataHost.PointerSize will probe the list of loaded assemblies /// to find an assembly that either requires 32 bit pointers or 64 bit pointers. If no such assembly is found, the default is 32 bit pointers. ///
searchPaths IEnumerable /// A collection of strings that are interpreted as valid paths which are used to search for units. ///
searchInGAC bool /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. ///
return System

OpenBinaryDocument() public method

Open the binary document as a memory block in host dependent fashion. IMPORTANT: The lifetime of the memory block is the same as the lifetime of this host object. Be sure to call Dispose on the host object when it is no longer needed, otherwise files may stay locked, or resources such as large blocks of memory may remain allocated until the host's finalizer method runs.
When overridding this method, be sure to add any disposable objects to this.disposableObjectAllocatedByThisHost.
public OpenBinaryDocument ( IBinaryDocument sourceDocument ) : IBinaryDocumentMemoryBlock
sourceDocument IBinaryDocument The binary document that is to be opened.
return IBinaryDocumentMemoryBlock

OpenBinaryDocument() public method

Open the child binary document within the context of parent source document.as a memory block in host dependent fashion For example: in multimodule assemblies the main module will be parentSourceDocument, where as other modules will be child documents. IMPORTANT: The lifetime of the memory block is the same as the lifetime of this host object. Be sure to call Dispose on the host object when it is no longer needed, otherwise files may stay locked, or resources such as large blocks of memory may remain allocated until the host's finalizer method runs.
When overridding this method, be sure to add any disposable objects to this.disposableObjectAllocatedByThisHost.
public OpenBinaryDocument ( IBinaryDocument parentSourceDocument, string childDocumentName ) : IBinaryDocumentMemoryBlock
parentSourceDocument IBinaryDocument The source document indicating the child document location.
childDocumentName string The name of the child document.
return IBinaryDocumentMemoryBlock

Redirect() public method

Provides the host with an opportunity to add, remove or substitute assembly references in the given list. This avoids the cost of rewriting the entire unit in order to make such changes.
public Redirect ( IUnit referringUnit, IEnumerable assemblyReferences ) : IEnumerable
referringUnit IUnit The unit that contains these references.
assemblyReferences IEnumerable The assembly references to substitute.
return IEnumerable

Redirect() public method

Provides the host with an opportunity to substitute one named type reference for another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.
public Redirect ( IUnit referringUnit, INamedTypeReference typeReference ) : INamedTypeReference
referringUnit IUnit The unit that contains the reference.
typeReference INamedTypeReference A named type reference encountered during metadata reading.
return INamedTypeReference

ResolvingAssemblyReference() public method

This method is called when the assembly reference is being resolved and its not already loaded by the Read/Write host.
public ResolvingAssemblyReference ( IUnit referringUnit, Microsoft.Cci.AssemblyIdentity referencedAssembly ) : void
referringUnit IUnit The unit that is referencing the assembly.
referencedAssembly Microsoft.Cci.AssemblyIdentity Assembly identity for the assembly being referenced.
return void

ResolvingModuleReference() public method

This method is called when the module reference is being resolved and its not already loaded by the Read/Write host.
public ResolvingModuleReference ( IUnit referringUnit, Microsoft.Cci.ModuleIdentity referencedModule ) : void
referringUnit IUnit The unit that is referencing the module.
referencedModule Microsoft.Cci.ModuleIdentity Module identity for the assembly being referenced.
return void

Rewrite() public method

Provides the host with an opportunity to substitute a custom attribute with another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.
public Rewrite ( IUnit containingUnit, ICustomAttribute customAttribute ) : ICustomAttribute
containingUnit IUnit The unit that contains the custom attribute.
customAttribute ICustomAttribute The custom attribute to rewrite (fix up).
return ICustomAttribute

Rewrite() public method

Provides the host with an opportunity to substitute one method definition for another during metadata reading. This avoids the cost of rewriting the entire unit in order to make such changes.
public Rewrite ( IUnit containingUnit, IMethodDefinition methodDefinition ) : IMethodDefinition
containingUnit IUnit The unit that is defines the method.
methodDefinition IMethodDefinition A method definition encountered during metadata reading.
return IMethodDefinition

StartGuessingGame() public method

Called by the metadata reader when it is about to start parsing a custom attribute blob.
public StartGuessingGame ( ) : void
return void

TryNextPermutation() public method

Called by the metadata reader when it has unsucessfully tried to parse a custom attribute blob and it now needs to try a new permutation. Returns false if no more perumations are possible.
public TryNextPermutation ( ) : bool
return bool

WinGuessingGame() public method

Called by the metadata reader when it has successfully parsed a custom attribute blob.
public WinGuessingGame ( ) : void
return void

Property Details

disposableObjectAllocatedByThisHost protected property

A list of all of the IDisposable object that have been allocated by this host.
protected List disposableObjectAllocatedByThisHost
return List