Beispiel #1
0
        public string Signature(bool forSorting)
        {
            string prefix = forSorting ? ClassPath + "." : "";

            if (!forSorting && IsStatic)
            {
                prefix = "static ";
            }

            {
                MethodDeclarationSyntax method = Member as MethodDeclarationSyntax;
                if (method != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}.{method.Identifier}(");
                    }
                    else
                    {
                        signature.Append($"{prefix}{method.ReturnType} {method.Identifier}(");
                    }
                    int parameterCount = method.ParameterList.Parameters.Count;
                    for (int i = 0; i < parameterCount; i++)
                    {
                        if (i > 0)
                        {
                            signature.Append(", ");
                        }
                        var parameter = method.ParameterList.Parameters[i];
                        for (int j = 0; j < parameter.Modifiers.Count; j++)
                        {
                            signature.Append(parameter.Modifiers[j].Text);
                            signature.Append(" ");
                        }

                        string paramType  = parameter.Type.ToString();
                        int    angleIndex = paramType.IndexOf('<');
                        if (angleIndex > 0)
                        {
                            string prefixType  = paramType.Substring(0, angleIndex);
                            int    prefixIndex = prefixType.LastIndexOf('.');
                            if (prefixIndex > 0)
                            {
                                prefixType = prefixType.Substring(prefixIndex + 1);
                            }
                            string genericType  = paramType.Substring(angleIndex + 1);
                            int    genericIndex = genericType.LastIndexOf('.');
                            if (genericIndex > 0)
                            {
                                genericType = genericType.Substring(genericIndex + 1);
                            }
                            paramType = prefixType + "<" + genericType;
                        }
                        else
                        {
                            int index = paramType.LastIndexOf('.');
                            if (index > 0)
                            {
                                paramType = paramType.Substring(index + 1);
                            }
                        }
                        signature.Append(paramType);
                        if (!forSorting)
                        {
                            signature.Append($" {parameter.Identifier}");
                        }
                    }
                    signature.Append(")");
                    return(signature.ToString());
                }
            }
            {
                PropertyDeclarationSyntax property = Member as PropertyDeclarationSyntax;
                if (property != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}.{property.Identifier}");
                    }
                    else
                    {
                        string proptype = $"{property.Type}";
                        int    index    = proptype.LastIndexOf('.');
                        if (index > 0)
                        {
                            proptype = proptype.Substring(index + 1);
                        }
                        signature.Append($"{prefix}{proptype} {property.Identifier}");
                    }
                    return(signature.ToString());
                }
            }
            {
                EventDeclarationSyntax evt = Member as EventDeclarationSyntax;
                if (evt != null)
                {
                    var signature = new System.Text.StringBuilder();
                    signature.Append($"{prefix}{evt.Identifier}");
                    return(signature.ToString());
                }
            }
            {
                OperatorDeclarationSyntax op = Member as OperatorDeclarationSyntax;
                if (op != null)
                {
                    var signature = new System.Text.StringBuilder();
                    signature.Append($"{prefix}{op.OperatorToken}");
                    return(signature.ToString());
                }
            }
            {
                EventFieldDeclarationSyntax eventField = Member as EventFieldDeclarationSyntax;
                if (eventField != null)
                {
                    var    signature   = new System.Text.StringBuilder();
                    string declaration = eventField.ToString();
                    int    index       = declaration.LastIndexOf(' ');
                    declaration = declaration.Substring(index + 1, declaration.Length - 1 - (index + 1));
                    signature.Append($"{prefix}{declaration}");
                    return(signature.ToString());
                }
            }
            {
                ConstructorDeclarationSyntax constructor = Member as ConstructorDeclarationSyntax;
                if (constructor != null)
                {
                    var signature = new System.Text.StringBuilder();
                    if (forSorting)
                    {
                        signature.Append($"{ClassPath}(");
                    }
                    else
                    {
                        if (IsStatic)
                        {
                            signature.Append("static ");
                        }
                        var parent = new ParsedType(Member.Parent as BaseTypeDeclarationSyntax, null);
                        signature.Append($"{parent.Name}(");
                    }
                    int parameterCount = constructor.ParameterList.Parameters.Count;
                    for (int i = 0; i < parameterCount; i++)
                    {
                        if (i > 0)
                        {
                            signature.Append(", ");
                        }
                        var    parameter  = constructor.ParameterList.Parameters[i];
                        string paramType  = parameter.Type.ToString();
                        int    angleIndex = paramType.IndexOf('<');
                        if (angleIndex > 0)
                        {
                            string prefixType  = paramType.Substring(0, angleIndex);
                            int    prefixIndex = prefixType.LastIndexOf('.');
                            if (prefixIndex > 0)
                            {
                                prefixType = prefixType.Substring(prefixIndex + 1);
                            }
                            string genericType  = paramType.Substring(angleIndex + 1);
                            int    genericIndex = genericType.LastIndexOf('.');
                            if (genericIndex > 0)
                            {
                                genericType = genericType.Substring(genericIndex + 1);
                            }
                            paramType = prefixType + "<" + genericType;
                        }
                        else
                        {
                            int index = paramType.LastIndexOf('.');
                            if (index > 0)
                            {
                                paramType = paramType.Substring(index + 1);
                            }
                        }
                        signature.Append(paramType);
                        if (!forSorting)
                        {
                            signature.Append($" {parameter.Identifier}");
                        }
                    }
                    signature.Append(")");
                    return(signature.ToString());
                }
            }
            {
                EnumMemberDeclarationSyntax enumMember = Member as EnumMemberDeclarationSyntax;
                if (enumMember != null)
                {
                    var signature = enumMember.ToString();
                    var items     = signature.Split(new char[] { '\n' });
                    signature = items[items.Length - 1];
                    return(signature);
                }
            }
            throw new NotImplementedException();
        }