private MethodSymbol GetConstructedMethod( string source, string methodName, string[] serializedTypeArgumentNames, CSharpInstructionDecoder instructionDecoder ) { var compilation = CreateCompilationWithMscorlib45( source, options: TestOptions.DebugDll, assemblyName: nameof(InstructionDecoderTests) ); var runtime = CreateRuntimeInstance(compilation); var moduleInstances = runtime.Modules; var blocks = moduleInstances.SelectAsArray(m => m.MetadataBlock); compilation = blocks.ToCompilation( default(Guid), MakeAssemblyReferencesKind.AllAssemblies ); var frame = (PEMethodSymbol)GetMethodOrTypeBySignature(compilation, methodName); // Once we have the method token, we want to look up the method (again) // using the same helper as the product code. This helper will also map // async/iterator "MoveNext" methods to the original source method. MethodSymbol method = compilation.GetSourceMethod( ((PEModuleSymbol)frame.ContainingModule).Module.GetModuleVersionIdOrThrow(), frame.Handle ); if (serializedTypeArgumentNames != null) { Assert.NotEmpty(serializedTypeArgumentNames); var typeParameters = instructionDecoder.GetAllTypeParameters(method); Assert.NotEmpty(typeParameters); // Use the same helper method as the FrameDecoder to get the TypeSymbols for the // generic type arguments (rather than using EETypeNameDecoder directly). var typeArguments = instructionDecoder.GetTypeSymbols( compilation, method, serializedTypeArgumentNames ); if (!typeArguments.IsEmpty) { method = instructionDecoder.ConstructMethod( method, typeParameters, typeArguments ); } } return(method); }
private MethodSymbol GetConstructedMethod(string source, string methodName, string[] serializedTypeArgumentNames, CSharpInstructionDecoder instructionDecoder) { var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: nameof(InstructionDecoderTests)); var runtime = CreateRuntimeInstance(compilation); var moduleInstances = runtime.Modules; var blocks = moduleInstances.SelectAsArray(m => m.MetadataBlock); compilation = blocks.ToCompilation(); var frame = (PEMethodSymbol)GetMethodOrTypeBySignature(compilation, methodName); // Once we have the method token, we want to look up the method (again) // using the same helper as the product code. This helper will also map // async/iterator "MoveNext" methods to the original source method. MethodSymbol method = compilation.GetSourceMethod( ((PEModuleSymbol)frame.ContainingModule).Module.GetModuleVersionIdOrThrow(), MetadataTokens.GetToken(frame.Handle)); if (serializedTypeArgumentNames != null) { Assert.NotEmpty(serializedTypeArgumentNames); var typeParameters = instructionDecoder.GetAllTypeParameters(method); Assert.NotEmpty(typeParameters); var typeNameDecoder = new EETypeNameDecoder(compilation, (PEModuleSymbol)method.ContainingModule); // Use the same helper method as the FrameDecoder to get the TypeSymbols for the // generic type arguments (rather than using EETypeNameDecoder directly). var typeArguments = instructionDecoder.GetTypeSymbols(compilation, method, serializedTypeArgumentNames); if (!typeArguments.IsEmpty) { method = instructionDecoder.ConstructMethod(method, typeParameters, typeArguments); } } return method; }