Ejemplo n.º 1
0
 public string WriteTypeScript(CodeConversionOptions options, Context context)
 =>     // name
 Name.TransformIf(options.ToCamelCase, StringUtilities.ToCamelCase)
 // separator
 + "?".If(Type.IsOptional(options, out _)) + ": "
 // type
 + (Type.IsOptional(options, out var of) ? of.WriteTypeScript(options, context) : Type.WriteTypeScript(options, context)) + ";";
Ejemplo n.º 2
0
        public string ConvertToTypeScript(string code, CodeConversionOptions options)
        {
            var root = CSharpSyntaxTree.ParseText(code).GetCompilationUnitRoot();

            var converted = _syntaxTreeConverter.Convert(root);

            return(converted.WriteTypeScript(options));
        }
Ejemplo n.º 3
0
        public string WriteTypeScript(CodeConversionOptions options, Context context)
        {
            var value = options.StringEnums
                ? Name.TransformIf(options.EnumStringToCamelCase, StringUtilities.ToCamelCase)
                        .InQuotes(options.QuotationMark)
                : Value?.SquashWhistespace();

            return(Name + (" = " + value).If(!string.IsNullOrWhiteSpace(value)));
        }
Ejemplo n.º 4
0
 public override string WriteTypeScript(CodeConversionOptions options, Context context)
 =>      // keywords
 "export ".If(options.Export) + "enum "
 // name
 + Name
 // body
 + " {" + NewLine
 // members
 + Members.WriteTypeScript(options, context).Indent(options.UseTabs, options.TabSize).LineByLine(separator: ",") + NewLine
 + "}";
 public string WriteTypeScript(CodeConversionOptions options, Context context)
 =>     // name
 (JsonPropertyName?
  .TransformIf(!JsonPropertyName.IsValidIdentifier(), StringUtilities.InQuotes(options.QuotationMark))
  .EscapeBackslashes()
  ?? Name.TransformIf(options.ToCamelCase, StringUtilities.ToCamelCase))
 // separator
 + "?".If(Type.IsOptional(options, out _)) + ": "
 // type
 + (Type.IsOptional(options, out var of) ? of.WriteTypeScript(options, context) : Type.WriteTypeScript(options, context)) + ";";
        public string WriteTypeScript(CodeConversionOptions options, Context context)
        {
            var name = Name.TransformIf(options.ToCamelCase, StringUtilities.ToCamelCase);

            return(name + (
                       options.EnumAsString
                    ? " = " + name.InQuotes(options.QuotationMark)
                    : !string.IsNullOrWhiteSpace(Value)
                        ? " = " + Value?.SquashWhistespace()
                        : string.Empty
                       ));
        }
        public string WriteTypeScript(CodeConversionOptions options)
        {
            var context = new Context();

            return // imports
                   ((Imports.Select(i =>
                   // type
                                    "import { " + i.TransformIf(options.RemoveInterfacePrefix, StringUtilities.RemoveInterfacePrefix) + " }"
                   // module
                                    + " from " + ("./" + ModuleNameTransformation.Transform(i, options)).InQuotes(options.QuotationMark) + ";")
                     .Distinct().LineByLine()
                     + EmptyLine).If(Imports.Any() && options.ImportGenerationMode != ImportGenerationMode.None)
                    // types
                    + RootNodes.WriteTypeScript(options, context).ToEmptyLineSeparatedList());
        }
Ejemplo n.º 8
0
        public override string WriteTypeScript(CodeConversionOptions options, Context context)
        {
            context = context.Clone();
            context.GenericTypeParameters = GenericTypeParameters;

            // keywords
            return("export ".If(options.Export) + "interface "
                   // name
                   + Name.TransformIf(options.RemoveInterfacePrefix, StringUtilities.RemoveInterfacePrefix)
                   // generic type parameters
                   + ("<" + GenericTypeParameters.ToCommaSepratedList() + ">").If(GenericTypeParameters.Any())
                   // base types
                   + (" extends " + BaseTypes.WriteTypeScript(options, context).ToCommaSepratedList()).If(BaseTypes.Any())
                   // body
                   + " {" + NewLine
                   // fields
                   + Fields.WriteTypeScript(options, context).Indent(options.UseTabs, options.TabSize).LineByLine() + NewLine
                   + "}");
        }
Ejemplo n.º 9
0
 public virtual bool IsOptional(CodeConversionOptions options, out TypeNode of)
 {
     of = null;
     return(false);
 }
Ejemplo n.º 10
0
 public override bool IsOptional(CodeConversionOptions options, out TypeNode of)
 {
     of = this;
     return(options.OptionalReferenceTypes);
 }
Ejemplo n.º 11
0
 public override string WriteTypeScript(CodeConversionOptions options, Context context)
 => "{ [key: " + Key.WriteTypeScript(options, context) + "]: " + Value.WriteTypeScript(options, context) + "; }";
Ejemplo n.º 12
0
 public override string WriteTypeScript(CodeConversionOptions options, Context context) => "string";
Ejemplo n.º 13
0
 public override string WriteTypeScript(CodeConversionOptions options, Context context)
 =>     // name
 Name.TransformIf(options.RemoveInterfacePrefix && !context.GenericTypeParameters.Contains(Name), StringUtilities.RemoveInterfacePrefix)
 // generic type parameters
 + "<" + Arguments.WriteTypeScript(options, context).ToCommaSepratedList() + ">";
Ejemplo n.º 14
0
 public override string WriteTypeScript(CodeConversionOptions options) => "any";
Ejemplo n.º 15
0
 public override string WriteTypeScript(CodeConversionOptions options, Context context)
 => Name.TransformIf(options.RemoveInterfacePrefix && !context.GenericTypeParameters.Contains(Name), StringUtilities.RemoveInterfacePrefix);
Ejemplo n.º 16
0
 public string WriteTypeScript(CodeConversionOptions options)
 => "export ".If(options.Export) + "interface " + Name.RemoveInterfacePrefix() + ("<" + GenericTypeParameters.ToCommaSepratedList() + ">").If(GenericTypeParameters.Any()) + (" extends " + BaseTypes.Select(e => e.WriteTypeScript()).ToCommaSepratedList()).If(BaseTypes.Any()) + " {" + NewLine
 + Fields.Select(f => f.WriteTypeScript()).Indent(options.UseTabs, options.TabSize).LineByLine() + NewLine
 + "}";
Ejemplo n.º 17
0
 public string WriteTypeScript(CodeConversionOptions options)
 => string.Join(EmptyLine, RootNodes.Select(t => t.WriteTypeScript(options)));
 public override bool IsUnionType(CodeConversionOptions options) => true;
Ejemplo n.º 19
0
 public override string WriteTypeScript(CodeConversionOptions options)
 => "{ " + Elements.Select(e => e.WriteTypeScript(options)).ToSpaceSepratedList() + " }";
Ejemplo n.º 20
0
 public override string WriteTypeScript(CodeConversionOptions options)
 => options.ConvertDatesTo == DateOutputType.String ? "string"
     : options.ConvertDatesTo == DateOutputType.Date ? "Date"
     : options.ConvertDatesTo == DateOutputType.Union ? "string | Date"
     : throw new ArgumentException();
Ejemplo n.º 21
0
 public virtual bool IsUnionType(CodeConversionOptions options) => false;
Ejemplo n.º 22
0
 public abstract string WriteTypeScript(CodeConversionOptions options);
 public override string WriteTypeScript(CodeConversionOptions options, Context context)
 => Of.WriteTypeScript(options, context) + " | null";
 public override bool IsOptional(CodeConversionOptions options, out TypeNode of)
 {
     of = Of;
     return(options.ConvertNullablesTo == NullableOutputType.Undefined);
 }
Ejemplo n.º 25
0
 public override bool IsUnionType(CodeConversionOptions options)
 => options.ConvertDatesTo == DateOutputType.Union;
Ejemplo n.º 26
0
 public override string WriteTypeScript(CodeConversionOptions options)
 => Name.RemoveInterfacePrefix() + "<" + Arguments.Select(a => a.WriteTypeScript(options)).ToCommaSepratedList() + ">";
Ejemplo n.º 27
0
 public string WriteTypeScript(CodeConversionOptions options)
 => Name.ToCamelCase() + "?".If(Type.IsOptional(options, out _)) + ": " + (Type.IsOptional(options, out var of) ? of.WriteTypeScript(options) : Type.WriteTypeScript(options)) + ";";
Ejemplo n.º 28
0
 public static IEnumerable <string> WriteTypeScript(this IEnumerable <IWritableNode> nodes, CodeConversionOptions options, Context context)
 => nodes.Select(n => n.WriteTypeScript(options, context));
Ejemplo n.º 29
0
 public string ConvertToTypeScript(string code, CodeConversionOptions options)
 => _syntaxTreeConverter.Convert(CSharpSyntaxTree.ParseText(code).GetCompilationUnitRoot())
 .WriteTypeScript(options);
 public string WriteTypeScript(CodeConversionOptions options, Context context)
 => Name + (" = " + Value?.SquashWhistespace()).If(!string.IsNullOrWhiteSpace(Value));