예제 #1
0
        public virtual string WriteMethod(TsFunction netMethod, bool isGlobal)
        {
            var funParams     = string.Join(", ", netMethod.Parameters.Select(p => WriteField(p, false)));
            var returnTypeStr = WriteTypeName(netMethod.ReturnType);
            var returnType    = string.IsNullOrWhiteSpace(returnTypeStr) ? "void" : returnTypeStr;

            string accessModifier;

            if (isGlobal)
            {
                var exportStr = netMethod.IsPublic || netMethod.IsStatic ? "export " : "";
                accessModifier = $"{exportStr}function ";
            }
            else
            {
                var exportStr = !netMethod.IsPublic ? "private " : "";
                var staticStr = netMethod.IsStatic ? "static " : "";
                accessModifier = $"{exportStr}{staticStr}";
            }

            var body = netMethod.FunctionBody;

            return($"{accessModifier}{netMethod.Name}({funParams}): {returnType}" + _config.NewLine +
                   @"{" + _config.NewLine +
                   $@"{body.Indent(_indent)}" + _config.NewLine +
                   @"}");
            //TODO: if body is null then we should only render a method signature
        }
예제 #2
0
        public TsFunction Visit(IMethod me)
        {
            if (me is FakeMethod)
            {
                return(null);
            }
            TsFunction me2 = new TsFunction
            {
                Name       = SkJs.GetEntityJsName(me),
                IsStatic   = me.IsStatic,
                Parameters = me.Parameters.Select(Visit).ToList()
            };

            if (me.SymbolKind == SymbolKind.Constructor)
            {
                me2.Name = SkJs.GetEntityJsName(me);// "constructor";
                //if (me2.Name.StartsWith("."))
                //me2.IsConstructor = true;
            }
            else
            {
                me2.Type           = Visit(me.ReturnType);
                me2.TypeParameters = me.TypeParameters.Select(Visit).ToList();
            }
            return(me2);
        }
예제 #3
0
        public void Simple()
        {
            var tsName = new TsFunction
            {
                Name       = "SomeFunction",
                Parameters = new[]
                {
                    new TsFunctionParameter {
                        Name = "firstParameter", Type = new TsTypeReference("FirstType")
                    },
                    new TsFunctionParameter {
                        Name = "secondParameter", Type = new TsTypeReference("SecondType")
                    }
                },
                ReturnType = new TsTypeReference("ReturnType"),
                Body       = $"// not implemented{Environment.NewLine}//todo do"
            };

            tsName.ShouldBeTranslatedTo("function SomeFunction(firstParameter: FirstType, secondParameter: SecondType): ReturnType {",
                                        "    // not implemented",
                                        "    //todo do",
                                        "}");
        }