Exemple #1
0
 /// <summary>
 /// Formats an enumeration
 /// </summary>
 /// <param name="tsEnum">The enumeration</param>
 /// <returns>The string representation of the enumeration</returns>
 public virtual string Format(TsEnum tsEnum)
 {
     if (this.EnumsAsString)
     {
         return(this.FormatEnumAsStrings(tsEnum));
     }
     else
     {
         return(this.FormatEnumAsIntegers(tsEnum));
     }
 }
Exemple #2
0
 /// <summary>
 /// Formats an enumeration as string
 /// </summary>
 /// <param name="tsEnum">The enumeration</param>
 /// <returns>The string representation of the enumeration</returns>
 protected string FormatEnumAsStrings(TsEnum tsEnum)
 {
     using (var sbc = new StringBuilderContext(this))
     {
         this.WriteIndent();
         this.Write("type {0} = ", Format(tsEnum.Name));
         var values = tsEnum.Values.OrderBy(x => x.Key).ToArray();
         for (int i = 0; i < values.Length; i++)
         {
             var postFix = i < values.Length - 1 ? " | " : string.Empty;
             var entry   = values[i];
             this.Write("\'{0}\'{1}", entry.Key, postFix);
         }
         this.Write(";");
         this.WriteNewline();
         return(sbc.ToString());
     }
 }