You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExtensionsHeadings.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Xml.Linq;
  9. using Novacode;
  10. namespace Novacode
  11. {
  12. public static class ExtensionsHeadings
  13. {
  14. public static Paragraph Heading(this Paragraph paragraph, HeadingType headingType)
  15. {
  16. string StyleName = headingType.EnumDescription();
  17. paragraph.StyleName = StyleName;
  18. return paragraph;
  19. }
  20. public static string EnumDescription(this Enum enumValue)
  21. {
  22. if (enumValue == null || enumValue.ToString() == "0")
  23. {
  24. return string.Empty;
  25. }
  26. FieldInfo enumInfo = enumValue.GetType().GetField(enumValue.ToString());
  27. DescriptionAttribute[] enumAttributes = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
  28. if (enumAttributes.Length > 0)
  29. {
  30. return enumAttributes[0].Description;
  31. }
  32. else
  33. {
  34. return enumValue.ToString();
  35. }
  36. }
  37. }
  38. }