public override RtEnum GenerateNode(Type element, RtEnum result, TypeResolver resolver) { var resultEnum = base.GenerateNode(element, result, resolver); if (Context.Location.CurrentNamespace != null) { Context.Location.CurrentNamespace.CompilationUnits.Add(resultEnum); StringBuilder enumdescriptor = new StringBuilder(); enumdescriptor.AppendLine(); enumdescriptor.AppendLine($"const {resultEnum.EnumName} = new Map<number, string>(["); bool first = true; foreach (var resultEnumValue in resultEnum.Values) { if (!first) { enumdescriptor.AppendLine(","); } first = false; var enumDescription = resultEnumValue.EnumValueName.ToUpper(); //<- here you get your desired enum description string somehow enumdescriptor.Append($"[{resultEnum.EnumName}.{resultEnumValue.EnumValueName},'{enumDescription}']"); } enumdescriptor.AppendLine("]);"); Context.Location.CurrentNamespace.CompilationUnits.Add(new RtRaw(enumdescriptor.ToString())); } return(null); }
public override void Visit(RtEnum node) { if (node == null) { return; } Visit(node.Documentation); var prev = Context; Context = WriterContext.Enum; AppendTabs(); if (node.Export) { Write("export "); } if (node.IsConst) { Write("const "); } Write("enum "); Visit(node.EnumName); WriteLine(" { "); Tab(); foreach (var rtEnumValue in node.Values) { Visit(rtEnumValue); } UnTab(); AppendTabs(); WriteLine("}"); Context = prev; }
public override void Visit(RtEnum node) { if (node == null) { return; } Visit(node.Documentation); var prev = Context; Context = WriterContext.Enum; AppendTabs(); if (node.Export) { if (prev == WriterContext.Module) { Write("export "); } else { Write("declare "); } } if (node.IsConst) { Write("const "); } Write("enum "); Visit(node.EnumName); WriteLine(" {"); Tab(); var arr = node.Values.ToArray(); for (int i = 0; i < arr.Length; i++) { Visit(arr[i]); if (i != arr.Length - 1) { WriteLine(","); } if (!string.IsNullOrEmpty(arr[i].LineAfter)) { AppendTabs(); Write(arr[i].LineAfter); Br(); } } WriteLine(string.Empty); UnTab(); AppendTabs(); WriteLine("}"); Context = prev; }
/// <summary> /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to /// WriterWrapper (3rd argument) using TypeResolver if necessary /// </summary> /// <param name="element">Element code to be generated to output</param> /// <param name="result">Resulting node</param> /// <param name="resolver">Type resolver</param> public override RtEnum GenerateNode(Type element, RtEnum result, TypeResolver resolver) { var r = base.GenerateNode(element, result, resolver); if (r == null) { return(null); } foreach (var val in r.Values) { val.LineAfter = " "; } return(r); }
public override RtEnum GenerateNode(Type element, RtEnum result, TypeResolver resolver) { var resultEnum = base.GenerateNode(element, result, resolver); resultEnum.Export = true; if (Context.Location.CurrentNamespace != null) { Context.Location.CurrentNamespace.CompilationUnits.Add(resultEnum); var enumDescriptionsObject = GenerateEnumDescription(element, resultEnum); Context.Location.CurrentNamespace.CompilationUnits.Add(enumDescriptionsObject); } return(null); }
private RtRaw GenerateEnumDescription(Type element, RtEnum resultEnum) { var enumDescription = new StringBuilder(); enumDescription.AppendLine(); var enumName = resultEnum.EnumName; var tsType = $"{{[key in {enumName}]: {{long: string, short: string}}}}"; enumDescription.AppendLine($"export const {enumName}Descriptions: {tsType} = {{"); foreach (var resultEnumValue in resultEnum.Values) { var descriptionObj = GetElementDescription(element, resultEnumValue.EnumValueName); enumDescription.AppendLine($"\t[{enumName}.{resultEnumValue.EnumValueName}]: {descriptionObj},"); } enumDescription.AppendLine("};"); var item = new RtRaw(enumDescription.ToString()); return(item); }
public abstract void Visit(RtEnum node);
public override void Visit(RtEnum node) { }
public abstract T Visit(RtEnum node);