internal IMarshallingInformation GetMarshallingInformation( MetadataObject metadataObject ) { uint fieldMarshalRowId = this.PEFileReader.FieldMarshalTable.GetFieldMarshalRowId(metadataObject.TokenValue); if (fieldMarshalRowId == 0) return Dummy.MarshallingInformation; FieldMarshalRow fieldMarshalRow = this.PEFileReader.FieldMarshalTable[fieldMarshalRowId]; MemoryBlock fieldMarshalMemoryBlock = this.PEFileReader.BlobStream.GetMemoryBlockAt(fieldMarshalRow.NativeType); MemoryReader memoryReader = new MemoryReader(fieldMarshalMemoryBlock); System.Runtime.InteropServices.UnmanagedType unmanagedType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte(); if (memoryReader.NotEndOfBytes) { if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.ByValArray) { uint numElements = (uint)memoryReader.ReadCompressedUInt32(); System.Runtime.InteropServices.UnmanagedType elementType = System.Runtime.InteropServices.UnmanagedType.AsAny; if (memoryReader.NotEndOfBytes) elementType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte(); return new ByValArrayMarshallingInformation(elementType, numElements); } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.CustomMarshaler) { string marshallerName; string marshallerArgument; memoryReader.ReadInt16(); // Deliberate Skip... int byteLen = memoryReader.ReadCompressedUInt32(); if (byteLen == -1 || byteLen == 0) marshallerName = string.Empty; else marshallerName = memoryReader.ReadUTF8WithSize(byteLen); ITypeReference/*?*/ marshaller = this.GetSerializedTypeNameAsTypeReference(marshallerName); if (marshaller == null) marshaller = Dummy.TypeReference; byteLen = memoryReader.ReadCompressedUInt32(); if (byteLen == -1 || byteLen == 0) marshallerArgument = string.Empty; else marshallerArgument = memoryReader.ReadUTF8WithSize(byteLen); return new CustomMarshallingInformation(marshaller, marshallerArgument); } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.LPArray) { System.Runtime.InteropServices.UnmanagedType elementType = (System.Runtime.InteropServices.UnmanagedType)memoryReader.ReadByte(); int paramIndex = -1; uint flag = 0; uint numElements = 0; if (memoryReader.NotEndOfBytes) paramIndex = (int)memoryReader.ReadCompressedUInt32(); if (memoryReader.NotEndOfBytes) numElements = (uint)memoryReader.ReadCompressedUInt32(); if (memoryReader.NotEndOfBytes) { flag = (uint)memoryReader.ReadCompressedUInt32(); if (flag == 0) { //TODO: check that paramIndex is 0 paramIndex = -1; //paramIndex is just a place holder so that numElements can be present } } return new LPArrayMarshallingInformation(elementType, paramIndex, numElements); } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.SafeArray) { System.Runtime.InteropServices.VarEnum elementType = (System.Runtime.InteropServices.VarEnum)memoryReader.ReadByte(); string subType = string.Empty; if (memoryReader.NotEndOfBytes) { int byteLen = memoryReader.ReadCompressedUInt32(); if (byteLen > 0) subType = memoryReader.ReadUTF8WithSize(byteLen); } ITypeReference/*?*/ subTypeRef = this.GetSerializedTypeNameAsTypeReference(subType); if (subTypeRef == null) subTypeRef = Dummy.TypeReference; return new SafeArrayMarshallingInformation(elementType, subTypeRef); } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.ByValTStr) { uint numElements = (uint)memoryReader.ReadCompressedUInt32(); return new ByValTStrMarshallingInformation(numElements); } else if (unmanagedType == System.Runtime.InteropServices.UnmanagedType.Interface) { uint iidParameterIndex = (uint)memoryReader.ReadCompressedUInt32(); return new IidParameterIndexMarshallingInformation(iidParameterIndex); } else { //TODO: error blob should not have extra info unless one of the above types. } } return new SimpleMarshallingInformation(unmanagedType); }