예제 #1
0
 /// <summary>
 /// This method tries to resolves the give namespace type reference as an exported type.
 /// </summary>
 /// <param name="namespaceTypeReference"></param>
 internal ExportedTypeAliasBase/*?*/ TryToResolveNamespaceTypeReferenceAsExportedType(NamespaceTypeRefReference namespaceTypeReference) {
   uint typeRefRowId = namespaceTypeReference.TypeRefRowId;
   if (typeRefRowId == 0) return null;
   TypeRefRow typeRefRow = this.PEFileReader.TypeRefTable[typeRefRowId];
   IName namespaceName = this.GetNameFromOffset(typeRefRow.Namespace);
   IName typeName = this.GetNameFromOffset(typeRefRow.Name);
   uint resolutionScope = typeRefRow.ResolutionScope;
   if (resolutionScope == 0) //The reference is to something in this module
     return this.TryToResolveAsNamespaceTypeAlias(namespaceName, typeName);
   uint tokenType = resolutionScope & TokenTypeIds.TokenTypeMask;
   if (tokenType == TokenTypeIds.AssemblyRef) { //Only assemblies can have aliases
     uint rowId = resolutionScope & TokenTypeIds.RIDMask;
     AssemblyReference/*?*/ assemRef = this.GetAssemblyReferenceAt(rowId);
     if (assemRef == null) return null;
     var internalAssembly = assemRef.ResolvedAssembly as Assembly;
     if (internalAssembly != null) {
       PEFileToObjectModel assemblyPEFileToObjectModel = internalAssembly.PEFileToObjectModel;
       return assemblyPEFileToObjectModel.TryToResolveAsNamespaceTypeAlias(namespaceName, typeName);
     }
     //Since we are not able to resolve the assembly reference, we cannot know if the referenced assembly has an alias, so we just give up and return null.
   }
   return null;
 }
예제 #2
0
 /// <summary>
 /// This method resolved the TypeRef as an exported type. i.e. the said type reference refers to the type
 /// in exported type table.
 /// </summary>
 /// <param name="moduleTypeRefReference"></param>
 /// <returns></returns>
 internal ExportedTypeAliasBase/*?*/ ResolveNamespaceTypeRefReferenceAsExportedType(
   NamespaceTypeRefReference moduleTypeRefReference
 ) {
   uint typeRefRowId = moduleTypeRefReference.TypeRefRowId;
   if (typeRefRowId == 0)
     return null;
   TypeRefRow typeRefRow = this.PEFileReader.TypeRefTable[typeRefRowId];
   IName namespaceName = this.GetNameFromOffset(typeRefRow.Namespace);
   IName typeName = this.GetNameFromOffset(typeRefRow.Name);
   uint resolutionScope = typeRefRow.ResolutionScope;
   if (resolutionScope == 0) {
     return this.ResolveExportedNamespaceType(namespaceName, typeName);
   }
   uint tokenType = resolutionScope & TokenTypeIds.TokenTypeMask;
   uint rowId = resolutionScope & TokenTypeIds.RIDMask;
   //  See if this type is part of another assembly's Exported type table
   if (tokenType == TokenTypeIds.AssemblyRef) {
     AssemblyReference/*?*/ assemRef = this.GetAssemblyReferenceAt(rowId);
     if (assemRef == null) {
       return null;
     }
     var internalAssembly = assemRef.ResolvedAssembly as Assembly;
     if (internalAssembly != null) {
       PEFileToObjectModel assemblyPEFileToObjectModel = internalAssembly.PEFileToObjectModel;
       return assemblyPEFileToObjectModel.ResolveExportedNamespaceType(namespaceName, typeName);
     }
   }
   return null;
 }