internal static PEMethodSymbol GetSourceMethod(this CSharpCompilation compilation, Guid moduleVersionId, MethodDefinitionHandle methodHandle) { var method = GetMethod(compilation, moduleVersionId, methodHandle); var metadataDecoder = new MetadataDecoder((PEModuleSymbol)method.ContainingModule); var containingType = method.ContainingType; if (GeneratedNameParser.TryParseSourceMethodNameFromGeneratedName(containingType.Name, GeneratedNameKind.StateMachineType, out var sourceMethodName)) { foreach (var member in containingType.ContainingType.GetMembers(sourceMethodName)) { if (member is PEMethodSymbol candidateMethod) { var module = metadataDecoder.Module; methodHandle = candidateMethod.Handle; string stateMachineTypeName; if (module.HasStringValuedAttribute(methodHandle, AttributeDescription.AsyncStateMachineAttribute, out stateMachineTypeName) || module.HasStringValuedAttribute(methodHandle, AttributeDescription.IteratorStateMachineAttribute, out stateMachineTypeName)) { if (metadataDecoder.GetTypeSymbolForSerializedType(stateMachineTypeName).OriginalDefinition.Equals(containingType)) { return(candidateMethod); } } } } } return(method); }
public override string FormatTypeName(Type type, CommonTypeNameFormatterOptions options) { string stateMachineName; if (GeneratedNameParser.TryParseSourceMethodNameFromGeneratedName(type.Name, GeneratedNameKind.StateMachineType, out stateMachineName)) { return(stateMachineName); } return(base.FormatTypeName(type, options)); }