Extension.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace TBL.CSharp.Base
  3. {
  4. public static partial class Extension
  5. {
  6. #if DEBUG
  7. /// <summary>
  8. /// 获取调用时的源代码行数
  9. /// </summary>
  10. public static int SourceLineNumber([System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0)
  11. {
  12. return lineNumber;
  13. }
  14. /// <summary>
  15. /// 获取调用时的文件路径
  16. /// </summary>
  17. public static string SourceFilePath([System.Runtime.CompilerServices.CallerFilePath] string fileName = "")
  18. {
  19. return fileName;
  20. }
  21. /// <summary>
  22. /// 源文件名变为生成源码文件名
  23. /// </summary>
  24. public static string SourceFileGeneratePath(string path)
  25. {
  26. var pi = path.LastIndexOf(".cs", StringComparison.Ordinal);
  27. if (pi >= 0)
  28. {
  29. return $"{path.Substring(0, pi)}.Generated.cs";
  30. }
  31. return $"{path}.Generated";
  32. }
  33. #endif
  34. }
  35. }