-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathIDataCollection.cs
64 lines (57 loc) · 1.85 KB
/
IDataCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Diagnostics.CodeAnalysis;
namespace WebApiClientCore
{
/// <summary>
/// 定义数据集合的接口
/// </summary>
public interface IDataCollection
{
/// <summary>
/// 获取记录条数
/// </summary>
int Count { get; }
/// <summary>
/// 返回是否包含指定的 key
/// </summary>
/// <param name="key">键</param>
/// <returns></returns>
bool ContainsKey(object key);
/// <summary>
/// 设置值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
void Set(object key, object? value);
/// <summary>
/// 读取指定的键并尝试转换为目标类型
/// 失败则返回目标类型的 default 值
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="key">键</param>
/// <returns></returns>
[return: MaybeNull]
TValue Get<TValue>(object key);
/// <summary>
/// 尝试获取值
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <returns></returns>
bool TryGetValue(object key, out object? value);
/// <summary>
/// 尝试获取值并转换为TValue类型
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <returns></returns>
bool TryGetValue<TValue>(object key, [MaybeNullWhen(false)] out TValue value);
/// <summary>
/// 尝试移除
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <returns></returns>
bool TryRemove(object key, out object? value);
}
}