Exemplo n.º 1
0
        private void WriteSignature(MethodDeclaration methodDeclaration, OverloadsCollection overloads, bool ignoreInterface)
        {
            string name = overloads.GetOverloadName(ignoreInterface);

            this.Write(name);

            bool needComma = false;
            var  isGeneric = methodDeclaration.TypeParameters.Count > 0;

            if (isGeneric)
            {
                this.Write("<");
                foreach (var p in methodDeclaration.TypeParameters)
                {
                    if (needComma)
                    {
                        this.WriteComma();
                    }

                    needComma = true;
                    this.Write(p.Name);
                }
                this.Write(">");

                this.WriteOpenParentheses();

                var comma = false;
                foreach (var p in methodDeclaration.TypeParameters)
                {
                    if (comma)
                    {
                        this.WriteComma();
                    }
                    this.Write(p.Name);
                    this.WriteColon();
                    this.WriteOpenBrace();
                    this.Write(JS.Fields.PROTOTYPE);
                    this.WriteColon();
                    this.Write(p.Name);

                    this.WriteCloseBrace();
                    comma = true;
                }
            }
            else
            {
                this.WriteOpenParentheses();
            }

            if (needComma && methodDeclaration.Parameters.Count > 0)
            {
                this.WriteComma();
            }

            this.EmitMethodParameters(methodDeclaration.Parameters, methodDeclaration);

            this.WriteCloseParentheses();

            this.WriteColon();

            var retType = BridgeTypes.ToTypeScriptName(methodDeclaration.ReturnType, this.Emitter);

            this.Write(retType);

            this.WriteSemiColon();
            this.WriteNewLine();
        }
Exemplo n.º 2
0
        private void WriteSignature(MethodDeclaration methodDeclaration, OverloadsCollection overloads, bool ignoreInterface, bool isInterface)
        {
            if (!isInterface && !methodDeclaration.HasModifier(Modifiers.Public))
            {
                return;
            }

            string name = overloads.GetOverloadName(ignoreInterface);

            Write(name);

            bool needComma = false;
            var  isGeneric = methodDeclaration.TypeParameters.Count > 0;

            if (isGeneric)
            {
                Write("<");
                foreach (var p in methodDeclaration.TypeParameters)
                {
                    if (needComma)
                    {
                        WriteComma();
                    }

                    needComma = true;
                    Write(p.Name);
                }
                Write(">");

                WriteOpenParentheses();

                var comma = false;
                foreach (var p in methodDeclaration.TypeParameters)
                {
                    if (comma)
                    {
                        WriteComma();
                    }
                    Write(p.Name);
                    WriteColon();
                    WriteOpenBrace();
                    Write(JS.Fields.PROTOTYPE);
                    WriteColon();
                    Write(p.Name);

                    WriteCloseBrace();
                    comma = true;
                }
            }
            else
            {
                WriteOpenParentheses();
            }

            if (needComma && methodDeclaration.Parameters.Count > 0)
            {
                WriteComma();
            }

            EmitMethodParameters(methodDeclaration.Parameters, methodDeclaration);

            WriteCloseParentheses();

            WriteColon();

            var retType = H5Types.ToTypeScriptName(methodDeclaration.ReturnType, Emitter);

            Write(retType);

            var resolveResult = Emitter.Resolver.ResolveNode(methodDeclaration.ReturnType);

            if (resolveResult != null && (resolveResult.Type.IsReferenceType.HasValue && resolveResult.Type.IsReferenceType.Value || resolveResult.Type.IsKnownType(KnownTypeCode.NullableOfT)))
            {
                Write(" | null");
            }

            WriteSemiColon();
            WriteNewLine();
        }