Skip to content

Commit 24c8e93

Browse files
committed
refactor(Config): 统一索引器实现,使用 TryGet 方法
将 int、long、string 类型的索引器统一改为调用 TryGet 方法,简化代码并保持行为一致。移除 int 索引器的边界检查,由 TryGet 处理无效 ID。
1 parent a26e5bb commit 24c8e93

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

Runtime/Config/Config/BaseDataTable.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,19 @@ public bool TryGet(string id, out T value)
8282
return StringDataMaps.TryGetValue(id, out value);
8383
}
8484

85-
public T this[int index]
85+
public T this[int id]
8686
{
87-
get
88-
{
89-
if (index >= Count || index < 0)
90-
{
91-
throw new IndexOutOfRangeException(nameof(index));
92-
}
93-
94-
return DataList[index];
95-
}
87+
get { return TryGet(id, out var value) ? value : null; }
9688
}
9789

9890
public T this[long id]
9991
{
100-
get { return Get(id); }
92+
get { return TryGet(id, out var value) ? value : null; }
10193
}
10294

103-
public T this[string index]
95+
public T this[string id]
10496
{
105-
get { return Get(index); }
97+
get { return TryGet(id, out var value) ? value : null; }
10698
}
10799

108100
public int Count

0 commit comments

Comments
 (0)