-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnumerableQuoteGenerator.cs
66 lines (56 loc) · 2.04 KB
/
EnumerableQuoteGenerator.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
65
66
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace JollyQuotes
{
/// <inheritdoc cref="IEnumerableQuoteGenerator"/>
/// <typeparam name="T">Type of <see cref="IQuote"/> this class can generate.</typeparam>
public abstract partial class EnumerableQuoteGenerator<T> : QuoteGenerator<T>, IEnumerableQuoteGenerator where T : class, IQuote
{
/// <summary>
/// Initializes a new instance of the <see cref="EnumerableQuoteGenerator{T}"/> class with a <paramref name="source"/> specified.
/// </summary>
/// <param name="source">Source of the quotes, e.g. a link, file name or raw text.</param>
/// <exception cref="ArgumentException"><paramref name="source"/> is <see langword="null"/> or empty.</exception>
protected EnumerableQuoteGenerator(string source) : base(source)
{
}
/// <inheritdoc cref="IEnumerableQuoteGenerator.GetAllQuotes()"/>
public abstract IEnumerable<T> GetAllQuotes();
/// <inheritdoc cref="IEnumerableQuoteGenerator.GetAllQuotes(string)"/>
public abstract IEnumerable<T> GetAllQuotes(string tag);
/// <inheritdoc cref="IEnumerableQuoteGenerator.GetAllQuotes(string[])"/>
public abstract IEnumerable<T> GetAllQuotes(params string[]? tags);
/// <summary>
/// Returns an <see cref="IEnumerator{T}"/> that iterates through all the available <see cref="IQuote"/>s.
/// </summary>
public virtual IEnumerator<T> GetEnumerator()
{
return GetAllQuotes().GetEnumerator();
}
IEnumerable<IQuote> IEnumerableQuoteGenerator.GetAllQuotes()
{
return GetAllQuotes().Cast<IQuote>();
}
IEnumerable<IQuote> IEnumerableQuoteGenerator.GetAllQuotes(string tag)
{
return GetAllQuotes(tag).Cast<IQuote>();
}
IEnumerable<IQuote> IEnumerableQuoteGenerator.GetAllQuotes(params string[]? tags)
{
return GetAllQuotes(tags).Cast<IQuote>();
}
IEnumerator<IQuote> IEnumerable<IQuote>.GetEnumerator()
{
foreach (T quote in GetAllQuotes())
{
yield return quote;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}