Example #1
0
        /// <summary>
        /// The declartion part of the method, e.g. 'private int MyMethod(in MyType type, out ThatType that)'
        /// </summary>
        public string GetDeclarationString()
        {
            return(_declarationCache ??= BuildString());

            string BuildString()
            {
                var str = new StringBuilder();

                str.Append(Accessibility.ToCodeString()); // private
                str.Append(' ');
                str.Append(ReturnType);                   // int
                str.Append(' ');
                if (!IsConstructor)
                {
                    str.Append(MethodName); // MyMethod
                }
                if (TypeParameters.Count > 0)
                {
                    str.Append('<');
                    str.Append(string.Join(",", TypeParameters.Select(x => x.GenericName)));
                    str.Append('>');
                }
                str.Append("(");
                str.Append(string.Join(", ", Arguments.Select(x => x.ToParamString())));
                str.Append(")");
                if (TypeParameters.All(x => !x.HasConstrain))
                {
                    return(str.ToString());
                }
                foreach (var generic in TypeParameters)
                {
                    if (!generic.HasConstrain)
                    {
                        continue;
                    }
                    str.Append("where");
                    str.Append(' ');
                    str.Append(generic.GenericName);
                    str.Append(" : ");
                    str.Append(string.Join(",", GetGenericsArgs(generic)));
                    str.Append(' ');
                }
                return(str.ToString());
            }