public override string ToString()
        {
            var builder = new TypescriptBuilder();

            if (Imports.Any())
            {
                foreach (var import in Imports)
                {
                    builder.Append(import, null).NewLine();
                }

                builder.NewLine();
            }

            foreach (var element in Elements)
            {
                if (element == null)
                {
                    continue;
                }

                element.Build(builder, null);

                if (element != Elements.LastOrDefault())
                {
                    builder.NewLine().NewLine();
                }
            }

            return(builder.ToString());
        }
Beispiel #2
0
        public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent)
        {
            if (Decorators.Any())
            {
                builder.NewLine();
            }
            builder.Join(Decorators, b => b.NewLine());
            if (Decorators.Any())
            {
                builder.NewLine();
            }

            if (parent == null)
            {
                builder.Append("var ").Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            if (HasGetter && parent is Class)
            {
                builder.Append(Get, this);
            }

            if (HasGetter && HasSetter)
            {
                builder.NewLine();
            }

            if (HasSetter && parent is Class)
            {
                builder.Append(Set, this);
            }

            if (!HasSetter && !HasGetter && parent != null || parent is Interface)
            {
                var modifiers = Modifiers.Distinct().OrderBy(m => !(m is IAccessor)).Select(m => m.ToString());
                builder.Join(modifiers, " ");

                if (Modifiers.Any())
                {
                    builder.Append(' ');
                }

                builder.Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            return(builder);
        }