• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ShimakazeProject / Shimakaze.Sdk / 7192713719

13 Dec 2023 08:24AM UTC coverage: 85.054% (+4.4%) from 80.643%
7192713719

push

github

frg2089
重构

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>

894 of 1095 branches covered (0.0%)

Branch coverage included in aggregate %.

674 of 831 new or added lines in 72 files covered. (81.11%)

1940 of 2237 relevant lines covered (86.72%)

74249.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.89
/src/Shimakaze.Sdk.Common/AsyncTextReader.cs
1
namespace Shimakaze.Sdk;
2

3
/// <summary>
4
/// 异步读取器
5
/// </summary>
6
/// <typeparam name="T"> </typeparam>
7
public abstract class AsyncTextReader<T> : IDisposable, IAsyncDisposable
8
{
9
    /// <summary>
10
    /// Leave Open
11
    /// </summary>
12
    private readonly bool _leaveOpen;
13

14
    private bool _disposedValue;
15

16
    /// <summary>
17
    /// 基础流
18
    /// </summary>
19
    public TextReader BaseReader { get; }
18✔
20

21
    /// <summary>
22
    /// 构造 Csf 读取器
23
    /// </summary>
24
    /// <param name="baseReader"> 基础流 </param>
25
    /// <param name="leaveOpen"> 退出时是否保持流打开 </param>
26
    protected AsyncTextReader(TextReader baseReader, bool leaveOpen = false)
12✔
27
    {
28
        BaseReader = baseReader;
12✔
29
        _leaveOpen = leaveOpen;
12✔
30
    }
12✔
31

32
    /// <inheritdoc />
33
    public void Dispose()
34
    {
35
        Dispose(disposing: true);
6✔
36
        GC.SuppressFinalize(this);
6✔
37
    }
6✔
38

39
    /// <inheritdoc />
40
    public async ValueTask DisposeAsync()
41
    {
NEW
42
        await DisposeAsyncCore().ConfigureAwait(false);
×
43

NEW
44
        Dispose(disposing: false);
×
NEW
45
        GC.SuppressFinalize(this);
×
NEW
46
    }
×
47

48
    /// <inheritdoc cref="ReadAsync(IProgress{float}?, CancellationToken)" />
49
    public virtual Task<T> ReadAsync() => ReadAsync(default, default);
6✔
50

51
    /// <inheritdoc cref="ReadAsync(IProgress{float}?, CancellationToken)" />
NEW
52
    public virtual Task<T> ReadAsync(CancellationToken cancellationToken) => ReadAsync(default, default);
×
53

54
    /// <inheritdoc cref="ReadAsync(IProgress{float}?, CancellationToken)" />
NEW
55
    public virtual Task<T> ReadAsync(IProgress<float>? progress) => ReadAsync(default, default);
×
56

57
    /// <summary>
58
    /// 读取
59
    /// </summary>
60
    /// <param name="progress"> 进度 </param>
61
    /// <param name="cancellationToken"> 取消 </param>
62
    /// <returns> </returns>
63
    public abstract Task<T> ReadAsync(IProgress<float>? progress = default, CancellationToken cancellationToken = default);
64

65
    /// <summary>
66
    /// 释放模式
67
    /// </summary>
68
    /// <param name="disposing"> </param>
69
    protected virtual void Dispose(bool disposing)
70
    {
71
        if (_disposedValue)
9!
NEW
72
            return;
×
73

74
        if (disposing)
9✔
75
        {
76
            if (!_leaveOpen)
6✔
77
                BaseReader.Dispose();
6✔
78
        }
79

80
        _disposedValue = true;
9✔
81
    }
9✔
82

83
    /// <summary>
84
    /// 释放模式
85
    /// </summary>
86
    protected virtual async ValueTask DisposeAsyncCore()
87
    {
NEW
88
        await Task.Run(() =>
×
NEW
89
        {
×
NEW
90
            if (!_leaveOpen)
×
NEW
91
                BaseReader.Dispose();
×
NEW
92
        });
×
NEW
93
    }
×
94

95
    /// <summary>
96
    /// 终结器
97
    /// </summary>
98
    ~AsyncTextReader()
99
    {
100
        Dispose(disposing: false);
3✔
101
    }
6✔
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc