Esempio n. 1
0
 /// <summary>Provides a simple way to order members by the set of parameters</summary>
 private string parametersString(TSMemberDescription m) => m.Parameters?.JoinedKVP((name, prm) => $"{name}: {GetTypeString(prm.Type, "")}");
Esempio n. 2
0
        private void writeMember(TSMemberDescription m, string ns, int indentationLevel, string memberName, bool isClass)
        {
            bool isConstructor = memberName == "<ctor>";

            writeJsDoc(m.JsDoc, indentationLevel, true);

            string accessModifier = "";

            if (m.Private)
            {
                if (!isClass)
                {
                    throw new InvalidOperationException("Interface members cannot be private");
                }
                accessModifier = "private ";
            }

            var @readonly = m.ReadOnly.GetValueOrDefault() ? "readonly " : "";

            string memberIdentifier;

            if (isConstructor)
            {
                memberIdentifier = isClass ? "constructor" : "new";
            }
            else
            {
                memberIdentifier = memberName;
                if (memberIdentifier.Contains(".") || memberIdentifier.In("constructor"))
                {
                    memberIdentifier = $"'{memberIdentifier}'";
                }
            }

            string genericParameters = "";

            if (m.GenericParameters?.Any() ?? false)
            {
                if (m.Parameters == null)
                {
                    throw new InvalidOperationException("Cannot have generic parameters on properties.");
                }
                genericParameters = $"<{m.GenericParameters.Joined(",", x => GetTypeString(x, ns, true))}>";
            }

            string parameterList = "";

            if (m.Parameters != null)
            {
                var parameters = m.Parameters.Select((kvp, index) => {
                    //ShDocVw has a Javascript keyword as one of the parameters
                    var parameterName = kvp.Key;
                    if (parameterName.In(jsKeywords))
                    {
                        parameterName = $"{parameterName}_{index}";
                    }
                    return(KVP(parameterName, kvp.Value));
                }).ToList();
                parameterList = "(" + parameters.Joined(", ", y => GetParameterString(y, ns)) + ")";
            }

            var returnType = isClass && isConstructor ? "" : $": {GetTypeString(m.ReturnType, ns)}";

            $"{accessModifier}{@readonly}{memberIdentifier}{genericParameters}{parameterList}{returnType};".AppendLineTo(sb, indentationLevel);
        }