Skip to content

Commit

Permalink
[修复]1. 修复索引获取异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Nov 4, 2024
1 parent ff70480 commit 06a405a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
38 changes: 29 additions & 9 deletions Runtime/Config/Config/BaseDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public T Get(int id)
{
LongDataMaps.TryGetValue(id, out T value);
return value;
}
}

public T Get(long id)
{
LongDataMaps.TryGetValue(id, out T value);
Expand All @@ -32,19 +33,38 @@ public T Get(string id)
return value;
}

public T this[int id] => Get(id);

public T this[long id] => Get(id);
public T this[int index]
{
get
{
if (index >= Count || index < 0)
{
throw new IndexOutOfRangeException(nameof(index));
}

public T this[string id] => Get(id);
return DataList[index];
}
}

public int Count => Math.Max(LongDataMaps.Count, StringDataMaps.Count);
public int Count
{
get { return Math.Max(LongDataMaps.Count, StringDataMaps.Count); }
}

public T FirstOrDefault => DataList.FirstOrDefault();
public T FirstOrDefault
{
get { return DataList.FirstOrDefault(); }
}

public T LastOrDefault => DataList.LastOrDefault();
public T LastOrDefault
{
get { return DataList.LastOrDefault(); }
}

public T[] All => DataList.ToArray();
public T[] All
{
get { return DataList.ToArray(); }
}

public T[] ToArray()
{
Expand Down
22 changes: 4 additions & 18 deletions Runtime/Config/Config/IDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface IDataTable<T> : IDataTable where T : class
/// <param name="id"></param>
/// <returns></returns>
T Get(int id);

/// <summary>
/// 根据ID获取对象
/// </summary>
Expand All @@ -49,25 +49,11 @@ public interface IDataTable<T> : IDataTable where T : class
T Get(string id);

/// <summary>
/// 根据ID获取对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T this[int id] { get; }

/// <summary>
/// 根据ID获取对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T this[long id] { get; }

/// <summary>
/// 根据ID获取对象
/// 根据列表索引获取对象
/// </summary>
/// <param name="id"></param>
/// <param name="index">索引值</param>
/// <returns></returns>
T this[string id] { get; }
T this[int index] { get; }

/// <summary>
/// 获取数据表中第一个对象
Expand Down

0 comments on commit 06a405a

Please sign in to comment.