-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnumerableQuoteResolver.cs
62 lines (55 loc) · 2.28 KB
/
EnumerableQuoteResolver.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
using System;
namespace JollyQuotes
{
/// <summary>
/// <see cref="IQuoteGenerator"/> that provides mechanism for enumerating through a set of available <see cref="IQuote"/>s using a <see cref="IResourceResolver"/>.
/// </summary>
/// <typeparam name="T">Type of <see cref="IQuote"/> this class can generate.</typeparam>
public abstract partial class EnumerableQuoteResolver<T> : EnumerableQuoteGenerator<T>, IQuoteService, IDisposable where T : class, IQuote
{
/// <inheritdoc/>
public IResourceResolver Resolver { get; }
/// <summary>
/// Determines whether the current instance has been already disposed.
/// </summary>
protected bool Disposed { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="EnumerableQuoteResolver{T}"/> class with an underlaying <paramref name="resolver"/> and <paramref name="source"/> specified.
/// </summary>
/// <param name="resolver"><see cref="IResourceResolver"/> that is used to access requested resources.</param>
/// <param name="source">Source of the quotes, e.g. a link, file name or raw text.</param>
/// <exception cref="ArgumentNullException"><paramref name="resolver"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="source"/> is <see langword="null"/> or empty.</exception>
protected EnumerableQuoteResolver(IResourceResolver resolver, string source) : base(source)
{
if (resolver is null)
{
throw Error.Null(nameof(resolver));
}
Resolver = resolver;
}
/// <summary>
/// Releases the unmanaged resources used by the <see cref="EnumerableQuoteResolver{T}"/> and optionally disposes of the managed resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases the unmanaged resources used by the <see cref="EnumerableQuoteResolver{T}"/> and optionally disposes of the managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources;<see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!Disposed)
{
if (disposing && Resolver is IDisposable d)
{
d.Dispose();
}
Disposed = true;
}
}
}
}