AssemblyExt.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. namespace Quadarax.Foundation.Core.Reflection.Extensions
  7. {
  8. public static class AssemblyExt
  9. {
  10. #region *** Private Fields ***
  11. #endregion
  12. #region *** Public Properties ***
  13. #endregion
  14. #region *** Constructors ***
  15. #endregion
  16. #region *** Public operations & overrides ***
  17. public static Version GetVersion(this Assembly oAssembly)
  18. {
  19. return oAssembly.GetName().Version;
  20. }
  21. public static string GetDescription(this Assembly oAssembly)
  22. {
  23. var oAttribute = oAssembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), true).FirstOrDefault();
  24. if (oAttribute == null)
  25. return string.Empty;
  26. return ((AssemblyDescriptionAttribute)oAttribute).Description;
  27. }
  28. public static string GetProduct(this Assembly oAssembly)
  29. {
  30. var oAttribute = oAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), true).FirstOrDefault();
  31. if (oAttribute == null)
  32. return string.Empty;
  33. return ((AssemblyProductAttribute)oAttribute).Product;
  34. }
  35. public static string GetCompany(this Assembly oAssembly)
  36. {
  37. var oAttribute = oAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true).FirstOrDefault();
  38. if (oAttribute == null)
  39. return string.Empty;
  40. return ((AssemblyCompanyAttribute)oAttribute).Company;
  41. }
  42. public static string GetCopyright(this Assembly oAssembly)
  43. {
  44. var oAttribute = oAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true).FirstOrDefault();
  45. if (oAttribute == null)
  46. return string.Empty;
  47. return ((AssemblyCopyrightAttribute)oAttribute).Copyright;
  48. }
  49. public static string GetTrademark(this Assembly oAssembly)
  50. {
  51. var oAttribute = oAssembly.GetCustomAttributes(typeof(AssemblyTrademarkAttribute), true).FirstOrDefault();
  52. if (oAttribute == null)
  53. return string.Empty;
  54. return ((AssemblyTrademarkAttribute)oAttribute).Trademark;
  55. }
  56. public static string GetAssemblyPath(this Assembly oAssembly)
  57. {
  58. return Path.GetDirectoryName(new Uri(oAssembly.Location).LocalPath) + Path.DirectorySeparatorChar;
  59. }
  60. public static IEnumerable<Type> GetTypesWithAttribute<TAttribute>(this Assembly oAssembly, bool bInherit)where TAttribute : System.Attribute
  61. {
  62. var types = oAssembly.GetTypes();
  63. return types.Where(x => x.IsDefined(typeof(TAttribute), bInherit)).ToArray();
  64. }
  65. #endregion
  66. #region *** Private operations & overrides ***
  67. #endregion
  68. }
  69. }