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 + "}"); }
public override string ToString() { if (IsPrimitive) { return(CSharpName); } string typename = ""; if (!IsEmpty) { typename = CSharpName; } if (typename == "") { typename = "object"; } if (IsArray) { typename = $"{ElementType?.ToString() ?? "object"}[]"; } else if (IsGenericType && GenericTypeParameters.Any()) { typename = Name.Split("`")[0] + "<"; foreach (LookupType t in GenericTypeParameters) { typename += t.ToString() + (GenericTypeParameters[GenericTypeParameters.Count() - 1] != t ? ", " : ""); } typename += ">"; } else { typename = CSharpName; } return(typename); }
public override string ToString() { if (IsPrimitive) { return(CSharpName); } StringBuilder typename = new StringBuilder(); if (!IsEmpty) { typename.Append(CSharpName); } if (IsArray) { typename.Clear(); typename.Append($"{ElementType?.ToString() ?? "object"}[]"); } else if (IsGenericType && GenericTypeParameters.Any()) { typename.Clear(); typename.Append(Name.Split("`")[0] + "<"); foreach (UnitorType t in GenericTypeParameters) { typename.Append(t.ToString() + (GenericTypeParameters[GenericTypeParameters.Count() - 1] != t ? ", " : "")); } typename.Append('>'); } if (typename.Length == 0) { typename.Append("object"); } return(typename.ToString()); }
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 + "}";