forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegatingEnumerable.cs
More file actions
70 lines (63 loc) · 2.83 KB
/
DelegatingEnumerable.cs
File metadata and controls
70 lines (63 loc) · 2.83 KB
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
67
68
69
70
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Web.Http;
namespace System.Net.Http.Formatting
{
/// <summary>
/// Helper class to serialize <see cref="IEnumerable{T}"/> types by delegating them through a concrete implementation."/>.
/// </summary>
/// <typeparam name="T">The interface implementing <see cref="IEnumerable{T}"/> to proxy.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Enumerable conveys the meaning of collection")]
public sealed class DelegatingEnumerable<T> : IEnumerable<T>
{
private IEnumerable<T> _source;
/// <summary>
/// Initialize a DelegatingEnumerable. This constructor is necessary for <see cref="System.Runtime.Serialization.DataContractSerializer"/> to work.
/// </summary>
public DelegatingEnumerable()
{
_source = Enumerable.Empty<T>();
}
/// <summary>
/// Initialize a DelegatingEnumerable with an <see cref="IEnumerable{T}"/>. This is a helper class to proxy <see cref="IEnumerable{T}"/> interfaces for <see cref="System.Xml.Serialization.XmlSerializer"/>.
/// </summary>
/// <param name="source">The <see cref="IEnumerable{T}"/> instance to get the enumerator from.</param>
public DelegatingEnumerable(IEnumerable<T> source)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
_source = source;
}
/// <summary>
/// Get the enumerator of the associated <see cref="IEnumerable{T}"/>.
/// </summary>
/// <returns>The enumerator of the <see cref="IEnumerable{T}"/> source.</returns>
public IEnumerator<T> GetEnumerator()
{
return _source.GetEnumerator();
}
/// <summary>
/// This method is not implemented but is required method for serialization to work. Do not use.
/// </summary>
/// <param name="item">The item to add. Unused.</param>
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "Required by XmlSerializer, never used.")]
public void Add(object item)
{
throw new NotImplementedException();
}
/// <summary>
/// Get the enumerator of the associated <see cref="IEnumerable{T}"/>.
/// </summary>
/// <returns>The enumerator of the <see cref="IEnumerable{T}"/> source.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return _source.GetEnumerator();
}
}
}