T4ModelInfo.cs 1.0 KB

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.Threading.Tasks;
  9. namespace T4
  10. {
  11. /// <summary>
  12. /// T4实体模型信息类
  13. /// </summary>
  14. public class T4ModelInfo
  15. {
  16. public string ModelName { get; set; }
  17. public string Name { get; set; }
  18. public string Description { get; set; }
  19. public IEnumerable<PropertyInfo> Properties { get; set; }
  20. public T4ModelInfo(Type modelType)
  21. {
  22. var nameSpace = modelType.Namespace;
  23. if (nameSpace==null)
  24. {
  25. return;
  26. }
  27. var index = nameSpace.LastIndexOf('.') + 1;
  28. ModelName = nameSpace.Substring(index, nameSpace.Length - index);
  29. Name = modelType.Name;
  30. var descAttributes = modelType.GetCustomAttributes(typeof(DescriptionAttribute), true);
  31. Description = descAttributes.Length == 1 ? ((DescriptionAttribute) descAttributes[0]).Description : Name;
  32. Properties = modelType.GetProperties();
  33. }
  34. }
  35. }