Example #1
0
            private ISourceMethod GetSourceMethod(IModule module, string parentType, string name, out string localName)
            {
                localName = name;
                string sourceParentType = parentType;

                int parentTypeLastSeparator = parentType.LastIndexOfAny(cTypeNameSeparators);

                if (parentTypeLastSeparator >= 0)
                {
                    string typeSimpleName = parentType.Substring(parentTypeLastSeparator + 1);

                    if (GeneratedNames.TryParseGeneratedName(typeSimpleName, out var genTypeNameKind, out _, out _))
                    {
                        sourceParentType = parentType.Remove(parentTypeLastSeparator);

                        // lambda display class names don't contain the method - need to parse the method name below

                        if (genTypeNameKind == StateMachineType)
                        {
                            if (GeneratedNames.TryParseSourceMethodNameFromGeneratedName(typeSimpleName, genTypeNameKind, out string sourceMethodName))
                            {
                                var sourceMethod = GetSourceMethod(module, sourceParentType, sourceMethodName, out localName);

                                localName += " [state machine]";

                                return(sourceMethod);
                            }
                        }
                    }
                }

                if (GeneratedNames.TryParseGeneratedName(name, out var genMethodNameKind, out _, out _))
                {
                    if (GeneratedNames.TryParseSourceMethodNameFromGeneratedName(name, genMethodNameKind, out string sourceMethodName))
                    {
                        var sourceMethod = GetSourceMethod(module, sourceParentType, sourceMethodName, out localName);

                        switch (genMethodNameKind)
                        {
                        case IteratorFinallyMethod:
                            localName += " [iterator finally]";
                            break;

                        case LambdaMethod:
                            localName += " [lambda]";
                            break;

                        case LocalFunction:
                            if (GeneratedNames.TryParseLocalFunctionNameFromGeneratedName(name, out string localFunctionName))
                            {
                                localName += "." + localFunctionName;
                            }
                            break;
                        }
                        return(sourceMethod);
                    }
                }

                return(new SourceMethod(module, parentType, name));
            }
Example #2
0
        internal override void AppendFullName(StringBuilder builder, MethodSymbol method)
        {
            var displayFormat =
                ((method.MethodKind == MethodKind.PropertyGet) || (method.MethodKind == MethodKind.PropertySet)) ?
                s_propertyDisplayFormat :
                DisplayFormat;

            var parts    = method.ToDisplayParts(displayFormat);
            var numParts = parts.Length;

            for (int i = 0; i < numParts; i++)
            {
                var part          = parts[i];
                var displayString = part.ToString();

                switch (part.Kind)
                {
                case SymbolDisplayPartKind.ClassName:
                    if (GeneratedNames.GetKind(displayString) != GeneratedNameKind.LambdaDisplayClass)
                    {
                        builder.Append(displayString);
                    }
                    else
                    {
                        // Drop any remaining display class name parts and the subsequent dot...
                        do
                        {
                            i++;
                        }while ((i < numParts) && parts[i].Kind != SymbolDisplayPartKind.MethodName);
                        i--;
                    }
                    break;

                case SymbolDisplayPartKind.MethodName:
                    GeneratedNameKind kind;
                    int openBracketOffset, closeBracketOffset;
                    if (GeneratedNames.TryParseGeneratedName(displayString, out kind, out openBracketOffset, out closeBracketOffset) &&
                        (kind == GeneratedNameKind.LambdaMethod))
                    {
                        builder.Append(displayString, openBracketOffset + 1, closeBracketOffset - openBracketOffset - 1);     // source method name
                        builder.Append('.');
                        builder.Append(AnonymousMethodName);
                        // NOTE: The old implementation only appended the first ordinal number.  Since this is not useful
                        // in uniquely identifying the lambda, we'll append the entire ordinal suffix (which may contain
                        // multiple numbers, as well as '-' or '_').
                        builder.Append(displayString.Substring(closeBracketOffset + 2));     // ordinal suffix (e.g. "__1")
                    }
                    else
                    {
                        builder.Append(displayString);
                    }
                    break;

                default:
                    builder.Append(displayString);
                    break;
                }
            }
        }