C# Class Microsoft.Cci.MetadataHostEnvironment

Provides a standard abstraction over the applications that host components that provide or consume objects from the metadata model.
Inheritance: IMetadataHost
Show file Open project: visualmutator/visualmutator

Public Methods

Method Description
AddLibPath ( string path ) : void

Adds a new directory (path) to the list of search paths for which to look in when searching for a unit to load.

FindAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : IAssembly

Finds the assembly that matches the given identifier among the already loaded set of assemblies, or a dummy assembly if no matching assembly can be found.

FindModule ( Microsoft.Cci.ModuleIdentity moduleIdentity ) : IModule

Finds the module that matches the given identifier among the already loaded set of modules, or a dummy module if no matching module can be found.

FindUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : IUnit

Finds the unit that matches the given identifier, or a dummy unit if no matching unit can be found.

GetLocalPath ( System assemblyName ) : string

Returns the CodeBase of the named assembly (which is a URL), except if the URL has the file scheme. In that case the URL is converted to a local file path that can be used by System.IO.Path methods.

LoadAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : IAssembly

The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.

LoadModule ( Microsoft.Cci.ModuleIdentity moduleIdentity ) : IModule

The module that matches the given reference, or a dummy module if no matching module can be found.

LoadUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : IUnit

The unit that matches the given identity, or a dummy unit if no matching unit can be found.

LoadUnitFrom ( string location ) : IUnit

Returns the unit that is stored at the given location, or a dummy unit if no unit exists at that location or if the unit at that location is not accessible. Implementations should do enough caching to avoid repeating work: this method gets called very often for already loaded units as part of the probing logic.

RegisterAsLatest ( IUnit unit ) : void

Registers the given unit as the latest one associated with the unit's location. Such units can then be discovered by clients via GetUnit.

RemoveUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : bool

Removes the unit with the given identity. Returns true iff the unitIdentity is found in the loaded units.

ReportError ( IErrorMessage error ) : void

Raises the CompilationErrors event with the given error wrapped up in an error event arguments object. The event is raised on a separate thread.

ReportErrors ( Microsoft errorEventArguments ) : void

Raises the Errors event with the given error event arguments. The event is raised on a separate thread.

UnifyAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : Microsoft.Cci.AssemblyIdentity

Default implementation of UnifyAssembly. Override this method to change the behavior.

UnifyAssembly ( IAssemblyReference assemblyReference ) : Microsoft.Cci.AssemblyIdentity

Default implementation of UnifyAssembly. Override this method to change the behavior.

Protected Methods

Method Description
GetContractAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity

Returns the identity of the assembly containing the Microsoft.Contracts.Contract, by asking each of the loaded units for its opinion on the matter and returning the opinion with the highest version number. If none of the loaded units have an opinion, the result is the same as CoreAssemblySymbolicIdentity.

GetCoreAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity

Returns the identity of the assembly containing the core system types such as System.Object, by asking each of the loaded units for its opinion on the matter and returning the opinion with the highest version number. If none of the loaded units have an opinion, the identity of the runtime executing the compiler itself is returned.

GetPlatformType ( ) : IPlatformType

Returns an object that provides a collection of references to types from the core platform, such as System.Object and System.String.

GetSystemCoreAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity

Returns an identity that is the same as CoreAssemblyIdentity, except that the name is "System.Core" and the version is at least 3.5.

GetTargetPlatformPointerSize ( ) : byte

Returns an opinion about the size of a pointer on the target runtime for the set of modules currently in this.unitCache. If none of the modules requires either 32 bit pointers or 64 bit pointers the result is 4 (i.e. 32 bit pointers). This method is only called if a host application has not explicitly provided the pointer size of the target platform.

MetadataHostEnvironment ( 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.

Probe ( string probeDir, Microsoft.Cci.AssemblyIdentity referencedAssembly ) : Microsoft.Cci.AssemblyIdentity

Looks in the specified probeDir to see if a file exists, first with the extension "dll" and then with the extensions "winmd" and "exe". Returns null if not found, otherwise constructs a new AssemblyIdentity

SynchronousReportErrors ( object state ) : void

Raises the Errors event with the given error event arguments.

Private Methods

Method Description
ObjectInvariant ( ) : void
ProbeAssemblyReference ( IUnit referringUnit, Microsoft.Cci.AssemblyIdentity referencedAssembly ) : Microsoft.Cci.AssemblyIdentity
ProbeModuleReference ( IUnit referringUnit, Microsoft.Cci.ModuleIdentity referencedModule ) : Microsoft.Cci.ModuleIdentity

Method Details

AddLibPath() public method

Adds a new directory (path) to the list of search paths for which to look in when searching for a unit to load.
public AddLibPath ( string path ) : void
path string
return void

FindAssembly() public method

Finds the assembly that matches the given identifier among the already loaded set of assemblies, or a dummy assembly if no matching assembly can be found.
public FindAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : IAssembly
assemblyIdentity Microsoft.Cci.AssemblyIdentity
return IAssembly

FindModule() public method

Finds the module that matches the given identifier among the already loaded set of modules, or a dummy module if no matching module can be found.
public FindModule ( Microsoft.Cci.ModuleIdentity moduleIdentity ) : IModule
moduleIdentity Microsoft.Cci.ModuleIdentity
return IModule

FindUnit() public method

Finds the unit that matches the given identifier, or a dummy unit if no matching unit can be found.
public FindUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : IUnit
unitIdentity Microsoft.Cci.UnitIdentity
return IUnit

GetContractAssemblySymbolicIdentity() protected method

Returns the identity of the assembly containing the Microsoft.Contracts.Contract, by asking each of the loaded units for its opinion on the matter and returning the opinion with the highest version number. If none of the loaded units have an opinion, the result is the same as CoreAssemblySymbolicIdentity.
protected GetContractAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity
return Microsoft.Cci.AssemblyIdentity

GetCoreAssemblySymbolicIdentity() protected method

Returns the identity of the assembly containing the core system types such as System.Object, by asking each of the loaded units for its opinion on the matter and returning the opinion with the highest version number. If none of the loaded units have an opinion, the identity of the runtime executing the compiler itself is returned.
protected GetCoreAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity
return Microsoft.Cci.AssemblyIdentity

GetLocalPath() public static method

Returns the CodeBase of the named assembly (which is a URL), except if the URL has the file scheme. In that case the URL is converted to a local file path that can be used by System.IO.Path methods.
public static GetLocalPath ( System assemblyName ) : string
assemblyName System The name of the assembly whose location is desired.
return string

GetPlatformType() protected method

Returns an object that provides a collection of references to types from the core platform, such as System.Object and System.String.
protected GetPlatformType ( ) : IPlatformType
return IPlatformType

GetSystemCoreAssemblySymbolicIdentity() protected method

Returns an identity that is the same as CoreAssemblyIdentity, except that the name is "System.Core" and the version is at least 3.5.
protected GetSystemCoreAssemblySymbolicIdentity ( ) : Microsoft.Cci.AssemblyIdentity
return Microsoft.Cci.AssemblyIdentity

GetTargetPlatformPointerSize() protected method

Returns an opinion about the size of a pointer on the target runtime for the set of modules currently in this.unitCache. If none of the modules requires either 32 bit pointers or 64 bit pointers the result is 4 (i.e. 32 bit pointers). This method is only called if a host application has not explicitly provided the pointer size of the target platform.
protected GetTargetPlatformPointerSize ( ) : byte
return byte

LoadAssembly() public method

The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.
public LoadAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : IAssembly
assemblyIdentity Microsoft.Cci.AssemblyIdentity
return IAssembly

LoadModule() public method

The module that matches the given reference, or a dummy module if no matching module can be found.
public LoadModule ( Microsoft.Cci.ModuleIdentity moduleIdentity ) : IModule
moduleIdentity Microsoft.Cci.ModuleIdentity
return IModule

LoadUnit() public method

The unit that matches the given identity, or a dummy unit if no matching unit can be found.
public LoadUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : IUnit
unitIdentity Microsoft.Cci.UnitIdentity
return IUnit

LoadUnitFrom() public abstract method

Returns the unit that is stored at the given location, or a dummy unit if no unit exists at that location or if the unit at that location is not accessible. Implementations should do enough caching to avoid repeating work: this method gets called very often for already loaded units as part of the probing logic.
public abstract LoadUnitFrom ( string location ) : IUnit
location string
return IUnit

MetadataHostEnvironment() protected method

Allocates an object that provides an abstraction over the application hosting compilers based on this framework.
protected MetadataHostEnvironment ( 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. May be null. ///
searchInGAC bool /// Whether the GAC (Global Assembly Cache) should be searched when resolving references. ///
return System

Probe() protected method

Looks in the specified probeDir to see if a file exists, first with the extension "dll" and then with the extensions "winmd" and "exe". Returns null if not found, otherwise constructs a new AssemblyIdentity
protected Probe ( string probeDir, Microsoft.Cci.AssemblyIdentity referencedAssembly ) : Microsoft.Cci.AssemblyIdentity
probeDir string
referencedAssembly Microsoft.Cci.AssemblyIdentity
return Microsoft.Cci.AssemblyIdentity

RegisterAsLatest() public method

Registers the given unit as the latest one associated with the unit's location. Such units can then be discovered by clients via GetUnit.
public RegisterAsLatest ( IUnit unit ) : void
unit IUnit The unit to register.
return void

RemoveUnit() public method

Removes the unit with the given identity. Returns true iff the unitIdentity is found in the loaded units.
public RemoveUnit ( Microsoft.Cci.UnitIdentity unitIdentity ) : bool
unitIdentity Microsoft.Cci.UnitIdentity
return bool

ReportError() public method

Raises the CompilationErrors event with the given error wrapped up in an error event arguments object. The event is raised on a separate thread.
public ReportError ( IErrorMessage error ) : void
error IErrorMessage The error to report.
return void

ReportErrors() public method

Raises the Errors event with the given error event arguments. The event is raised on a separate thread.
public ReportErrors ( Microsoft errorEventArguments ) : void
errorEventArguments Microsoft
return void

SynchronousReportErrors() protected method

Raises the Errors event with the given error event arguments.
protected SynchronousReportErrors ( object state ) : void
state object The error event arguments.
return void

UnifyAssembly() public method

Default implementation of UnifyAssembly. Override this method to change the behavior.
public UnifyAssembly ( Microsoft.Cci.AssemblyIdentity assemblyIdentity ) : Microsoft.Cci.AssemblyIdentity
assemblyIdentity Microsoft.Cci.AssemblyIdentity
return Microsoft.Cci.AssemblyIdentity

UnifyAssembly() public method

Default implementation of UnifyAssembly. Override this method to change the behavior.
public UnifyAssembly ( IAssemblyReference assemblyReference ) : Microsoft.Cci.AssemblyIdentity
assemblyReference IAssemblyReference
return Microsoft.Cci.AssemblyIdentity