Browse Source

优化代码,在type转换失败的时候输出详细Debug

main
coffee 5 months ago
parent
commit
912cde91c4
  1. 8
      Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs
  2. 20
      Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs
  3. 2
      Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs

8
Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.Cell.cs

@ -65,10 +65,10 @@ namespace Tools.ExcelResolver.Editor
} }
throw new Exception($"单元格转换失败 " + throw new Exception($"单元格转换失败 " +
$"className: '<color=darkblue>{className}</color>' " + $"className: '<color=cyan>{className}</color>' " +
$"FullAddress: <color=darkblue>{cell.FullAddress}</color> " + $"FullAddress: <color=cyan>{cell.FullAddress}</color> " +
$"Type: '<color=darkblue>{type.FieldWriteFormat}</color>' " + $"Type: '<color=cyan>{type.FieldWriteFormat}</color>' " +
$"Text: '<color=darkblue>{cell.Text}</color>' "); $"Text: '<color=cyan>{cell.Text}</color>' ");
} }
/// <summary> /// <summary>

20
Assets/Unity-Tools/ExcelResolver/Editor/Core/Util/ExcelResolverUtil.TType.cs

@ -1,12 +1,15 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using OfficeOpenXml;
namespace Tools.ExcelResolver.Editor namespace Tools.ExcelResolver.Editor
{ {
internal static partial class ExcelResolverUtil internal static partial class ExcelResolverUtil
{ {
private static TType[] _allTTypes; private static TType[] _allTTypes;
private static ExcelRange _currentCell;
private static string _currentClassName;
internal static TType[] GetAllTTypes() internal static TType[] GetAllTTypes()
{ {
@ -20,23 +23,28 @@ namespace Tools.ExcelResolver.Editor
/// <summary> /// <summary>
/// 更具类型字符串获取 TType /// 更具类型字符串获取 TType
/// </summary> /// </summary>
/// <param name="typeText"></param> /// <param name="targetText"></param>
/// <returns></returns> /// <returns></returns>
internal static TType GetTTypeByString(string typeText) internal static TType GetTTypeByString(string targetText, ExcelRange cell = null, string className = null)
{ {
_currentCell = cell ?? _currentCell;
typeText = typeText.ToLower(); _currentClassName = className ?? _currentClassName;
targetText = targetText.ToLower();
_allTTypes ??= GetAllTTypes(); _allTTypes ??= GetAllTTypes();
foreach (var tType in _allTTypes) foreach (var tType in _allTTypes)
{ {
if (tType.String2TType(typeText)) if (tType.String2TType(targetText))
{ {
return tType; return tType;
} }
} }
throw new Exception($"未找到类型 {typeText}"); throw new Exception($"type定义错误 " +
$"className: '<color=cyan>{_currentClassName}</color>' " +
$"FullAddress: <color=cyan>{_currentCell.FullAddress}</color> " +
$"Text: '<color=cyan>{_currentCell.Text}</color>' " +
$"targetText: '<color=cyan>{targetText}</color>'");
} }
} }
} }

2
Assets/Unity-Tools/ExcelResolver/Editor/ExcelResolverEditorWindow.ReadExcel.cs

@ -127,7 +127,7 @@ namespace Tools.ExcelResolver.Editor
colIndex = col, colIndex = col,
varName = cellText, varName = cellText,
typeString = worksheet.Cells[3, col].Text, typeString = worksheet.Cells[3, col].Text,
type = ExcelResolverUtil.GetTTypeByString(worksheet.Cells[3, col].Text), type = ExcelResolverUtil.GetTTypeByString(worksheet.Cells[3, col].Text, worksheet.Cells[3, col], classCodeData.className),
info = worksheet.Cells[4, col].Text, info = worksheet.Cells[4, col].Text,
description = worksheet.Cells[5, col].Text, description = worksheet.Cells[5, col].Text,
path = worksheet.Cells[6, col].Text, path = worksheet.Cells[6, col].Text,

Loading…
Cancel
Save