fork download
  1. using System;
  2. using System.ComponentModel;
  3.  
  4. public class Program {
  5. public static void Main() => Console.WriteLine(BBCodes.Bold.Wrap("StackOverflow"));
  6. }
  7.  
  8. public enum BBCodes {
  9. [Description("b")]
  10. Bold = 1,
  11. [Description("i")]
  12. Italic = 2
  13. }
  14.  
  15. public static class BBCodesExt {
  16. public static string Wrap(this BBCodes code, string contents) => $"[{code.ToStringDescription()}]{contents}[/{code.ToStringDescription()}]";
  17. public static string ToStringDescription(this BBCodes code) {
  18. var attributes = (DescriptionAttribute[])code.GetType().GetField(code.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
  19. return attributes.Length > 0 ? attributes[0].Description : "";
  20. }
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/123841/101
Success #stdin #stdout 0.02s 17820KB
stdin
Standard input is empty
stdout
[b]StackOverflow[/b]