void LoadNestedTypesOfType( TypeBase moduleType ) { uint currentClassRowId = moduleType.TypeDefRowId; uint numberOfNestedClassRows = this.PEFileReader.NestedClassTable.NumberOfRows; var moduleTypeArray = this.ModuleTypeDefArray; uint firstNestedClassRow = 0; uint nestedClassCounter = 0; for (uint i = 1; i <= numberOfNestedClassRows; ++i) { NestedClassRow nestedClassRow = this.PEFileReader.NestedClassTable[i]; if (nestedClassRow.EnclosingClass != currentClassRowId) continue; if (firstNestedClassRow == 0) firstNestedClassRow = i; nestedClassCounter++; // Check if its already created by someone else NestedType/*?*/ currType = moduleTypeArray[nestedClassRow.NestedClass] as NestedType; if (currType == null) { currType = this.CreateModuleNestedType(nestedClassRow.NestedClass, this.PEFileReader.TypeDefTable[nestedClassRow.NestedClass], moduleType); var redirectedType = this.ModuleReader.metadataReaderHost.Redirect(this.Module, currType); if (redirectedType == currType) moduleType.AddMember(currType); moduleTypeArray[nestedClassRow.NestedClass] = currType; this.RedirectedTypeDefArray[nestedClassRow.NestedClass] = redirectedType; this.ModuleTypeDefLoadState[nestedClassRow.NestedClass] = LoadState.Loaded; } } if (nestedClassCounter > 0) { var nestedTypes = new INestedTypeDefinition[nestedClassCounter]; uint j = 0; for (uint i = firstNestedClassRow; j < nestedClassCounter && i <= numberOfNestedClassRows; ++i) { NestedClassRow nestedClassRow = this.PEFileReader.NestedClassTable[i]; if (nestedClassRow.EnclosingClass != currentClassRowId) continue; nestedTypes[j++] = (INestedTypeDefinition)moduleTypeArray[nestedClassRow.NestedClass]; Contract.Assume(nestedTypes[j-1] != null); } Contract.Assume(j == nestedClassCounter); moduleType.nestedTypes = IteratorHelper.GetReadonly(nestedTypes); } }
EventDefinition CreateEvent( uint eventDefRowId, TypeBase parentModuleType ) { Debug.Assert(eventDefRowId > 0 && eventDefRowId <= this.PEFileReader.EventTable.NumberOfRows); EventRow eventRow = this.PEFileReader.EventTable[eventDefRowId]; IName eventName = this.GetNameFromOffset(eventRow.Name); EventDefinition moduleEvent = new EventDefinition(this, eventName, parentModuleType, eventDefRowId, eventRow.Flags); parentModuleType.AddMember(moduleEvent); return moduleEvent; }
PropertyDefinition CreateProperty( uint propertyDefRowId, TypeBase parentModuleType ) { Debug.Assert(propertyDefRowId > 0 && propertyDefRowId <= this.PEFileReader.PropertyTable.NumberOfRows); PropertyRow propertyRow = this.PEFileReader.PropertyTable[propertyDefRowId]; IName propertyName = this.GetNameFromOffset(propertyRow.Name); PropertyDefinition moduleProperty = new PropertyDefinition(this, propertyName, parentModuleType, propertyDefRowId, propertyRow.Flags); parentModuleType.AddMember(moduleProperty); return moduleProperty; }
IMethodDefinition CreateMethod( uint methodDefRowId, TypeBase parentModuleType ) { Debug.Assert(methodDefRowId > 0 && methodDefRowId <= this.PEFileReader.MethodTable.NumberOfRows); MethodRow methodRow = this.PEFileReader.MethodTable[methodDefRowId]; IName methodName = this.GetNameFromOffset(methodRow.Name); if ((methodRow.Flags & MethodFlags.AccessMask) == MethodFlags.CompilerControlledAccess) { //Methods that are compiler controlled access are excempted from duplicate checking and may thus have names that cause //their intern keys to clash with other methods. Avoid this by mangling the names of such methods. //compiler controlled methods are always referred to via their tokens, so this renaming is safe to do. methodName = NameTable.GetNameFor(methodName.Value+"$PST"+((int)TableIndices.Method+methodDefRowId)); } uint genericParamRowIdStart; uint genericParamRowIdEnd; this.GetGenericParamInfoForMethod(methodDefRowId, out genericParamRowIdStart, out genericParamRowIdEnd); IMethodDefinition moduleMethod; if (genericParamRowIdStart == 0) { moduleMethod = new NonGenericMethod(this, methodName, parentModuleType, methodDefRowId, methodRow.Flags, methodRow.ImplFlags); } else { moduleMethod = new GenericMethod(this, methodName, parentModuleType, methodDefRowId, methodRow.Flags, methodRow.ImplFlags, genericParamRowIdStart, genericParamRowIdEnd); } if (methodName.UniqueKey != this.ModuleReader._Deleted_.UniqueKey) { moduleMethod = this.ModuleReader.metadataReaderHost.Rewrite(this.Module, moduleMethod); parentModuleType.AddMember(moduleMethod); } return moduleMethod; }
FieldDefinition CreateField( uint fieldDefRowId, TypeBase parentModuleType ) { Debug.Assert(fieldDefRowId > 0 && fieldDefRowId <= this.PEFileReader.FieldTable.NumberOfRows); FieldRow fieldRow = this.PEFileReader.FieldTable[fieldDefRowId]; IName fieldName = this.GetNameFromOffset(fieldRow.Name); if ((fieldRow.Flags & FieldFlags.AccessMask) == FieldFlags.CompilerControlledAccess) { //Methods that are compiler controlled access are excempted from duplicate checking and may thus have names that cause //their intern keys to clash with other methods. Avoid this by mangling the names of such methods. //compiler controlled methods are always referred to via their tokens, so this renaming is safe to do. fieldName = NameTable.GetNameFor(fieldName.Value+"$PST"+((int)TableIndices.Field+fieldDefRowId)); } FieldDefinition moduleField = new FieldDefinition(this, fieldName, parentModuleType, fieldDefRowId, fieldRow.Flags); if (fieldName.UniqueKey != this.ModuleReader._Deleted_.UniqueKey) { parentModuleType.AddMember(moduleField); } return moduleField; }
MethodDefinition CreateMethod( uint methodDefRowId, TypeBase parentModuleType ) { Debug.Assert(methodDefRowId > 0 && methodDefRowId <= this.PEFileReader.MethodTable.NumberOfRows); MethodRow methodRow = this.PEFileReader.MethodTable[methodDefRowId]; IName methodName = this.GetNameFromOffset(methodRow.Name); uint genericParamRowIdStart; uint genericParamRowIdEnd; this.GetGenericParamInfoForMethod(methodDefRowId, out genericParamRowIdStart, out genericParamRowIdEnd); MethodDefinition moduleMethod; if (genericParamRowIdStart == 0) { moduleMethod = new NonGenericMethod(this, methodName, parentModuleType, methodDefRowId, methodRow.Flags, methodRow.ImplFlags); } else { moduleMethod = new GenericMethod(this, methodName, parentModuleType, methodDefRowId, methodRow.Flags, methodRow.ImplFlags, genericParamRowIdStart, genericParamRowIdEnd); } if (methodName.UniqueKey != this.ModuleReader._Deleted_.UniqueKey) { parentModuleType.AddMember(moduleMethod); } return moduleMethod; }
FieldDefinition CreateField( uint fieldDefRowId, TypeBase parentModuleType ) { Debug.Assert(fieldDefRowId > 0 && fieldDefRowId <= this.PEFileReader.FieldTable.NumberOfRows); FieldRow fieldRow = this.PEFileReader.FieldTable[fieldDefRowId]; IName fieldName = this.GetNameFromOffset(fieldRow.Name); FieldDefinition moduleField = new FieldDefinition(this, fieldName, parentModuleType, fieldDefRowId, fieldRow.Flags); if (fieldName.UniqueKey != this.ModuleReader._Deleted_.UniqueKey) { parentModuleType.AddMember(moduleField); } return moduleField; }
NestedType CreateModuleNestedType( uint typeDefRowId, TypeDefRow typeDefRow, TypeBase parentModuleType ) { IName typeName = this.GetNameFromOffset(typeDefRow.Name); if (typeDefRow.Namespace != 0) { IName namespaceName = this.GetNameFromOffset(typeDefRow.Namespace); typeName = this.NameTable.GetNameFor(namespaceName.Value+"."+typeName.Value); } uint genericParamRowIdStart; uint genericParamRowIdEnd; this.GetGenericParamInfoForType(typeDefRowId, out genericParamRowIdStart, out genericParamRowIdEnd); NestedType type; if (genericParamRowIdStart == 0) { type = new NonGenericNestedType(this, typeName, typeDefRowId, typeDefRow.Flags, parentModuleType); } else { IName unmangledTypeName = this.GetUnmangledNameFromOffset(typeDefRow.Name); type = new GenericNestedType(this, unmangledTypeName, typeDefRowId, typeDefRow.Flags, parentModuleType, typeName, genericParamRowIdStart, genericParamRowIdEnd); } parentModuleType.AddMember(type); return type; }