Пример #1
0
        private void WriteImplementationInterface(InteropType type)
        {
            this.Line($"export interface I{type.Name}Interop {{");
            this.Indent();

            foreach (Method method in type.Methods)
            {
                string returnType = method.ReturnType.IsDefault() ? "void" : method.ReturnType;
                this.Line($"{method.Name.ToLowerFirstChar()}({method.Parameters.Select(p => $"{p.Name}: {p.Type}").Join(", ")}): Promise<{returnType}>;");
            }

            this.Unbrace();
        }
Пример #2
0
        private void WriteInitializationMethod(InteropTypeCollection model)
        {
            foreach (InteropType type in model)
            {
                this.Line($"const {type.Name.ToLowerFirstChar()}: I{type.Name}Interop = new {type.Name}Interop();");
            }

            this.Blank();
            this.Line("(<any>global).JSInterop = {");
            this.Indent();

            for (int i = 0; i < model.Count; i++)
            {
                InteropType type = model[i];
                this.Line($"{type.Name}: {{");
                this.Indent();

                for (int j = 0; j < type.Methods.Count; j++)
                {
                    Method method     = type.Methods[j];
                    string parameters = method.Parameters.Select(p => $"{p.Name}: {p.Type}").Join(", ");
                    string returnType = method.ReturnType.IsDefault() ? "boolean" : method.ReturnType;

                    this.Line($"{method.Name.ToLowerFirstChar()}: async ({parameters}) : Promise<{returnType}> => {{");
                    this.Indent();

                    if (method.ReturnType.IsDefault())
                    {
                        this.Line($"await {type.Name.ToLowerFirstChar()}.{method.Name.ToLowerFirstChar()}({method.Parameters.Select(p => p.Name).Join(", ")});");
                        this.Line("return true;");
                    }
                    else
                    {
                        this.Line($"return await {type.Name.ToLowerFirstChar()}.{method.Name.ToLowerFirstChar()}({method.Parameters.Select(p => p.Name).Join(", ")});");
                    }

                    this.Unindent();
                    this.Line($"}}{(j + 1 < type.Methods.Count ? "," : string.Empty)}");
                }

                this.Unindent();
                this.Line($"}}{(i + 1 == model.Count ? string.Empty : ",")}");
            }

            this.Unindent();
            this.Line("};");
        }