|
| 1 | +using System.Collections; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Net; |
| 4 | + |
| 5 | +#if NET35 |
| 6 | +using Headers = System.Net.WebHeaderCollection; |
| 7 | +#else |
| 8 | +using Headers = System.Net.Http.Headers.HttpResponseHeaders; |
| 9 | +#endif |
| 10 | + |
| 11 | +namespace Twilio.Base |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Wrapper class that contains both the resource set and HTTP response headers. |
| 15 | + /// Implements IEnumerable to allow direct iteration over records. |
| 16 | + /// </summary> |
| 17 | + /// <typeparam name="T">The type of the resource</typeparam> |
| 18 | + public class ResourceSetWithHeaders<T> : IEnumerable<T> where T : Resource |
| 19 | + { |
| 20 | + /// <summary> |
| 21 | + /// The resource set containing the records |
| 22 | + /// </summary> |
| 23 | + public ResourceSet<T> Records { get; } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// HTTP response headers from the initial request |
| 27 | + /// </summary> |
| 28 | + public Headers Headers { get; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// HTTP status code from the initial request |
| 32 | + /// </summary> |
| 33 | + public HttpStatusCode StatusCode { get; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Create a new ResourceSetWithHeaders |
| 37 | + /// </summary> |
| 38 | + /// <param name="records">The resource set containing records</param> |
| 39 | + /// <param name="headers">HTTP response headers</param> |
| 40 | + /// <param name="statusCode">HTTP status code</param> |
| 41 | + public ResourceSetWithHeaders(ResourceSet<T> records, Headers headers, HttpStatusCode statusCode) |
| 42 | + { |
| 43 | + Records = records; |
| 44 | + Headers = headers; |
| 45 | + StatusCode = statusCode; |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Get enumerator for iterating over resources |
| 50 | + /// </summary> |
| 51 | + /// <returns>IEnumerator of resources</returns> |
| 52 | + public IEnumerator<T> GetEnumerator() |
| 53 | + { |
| 54 | + return Records.GetEnumerator(); |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Get enumerator for iterating over resources |
| 59 | + /// </summary> |
| 60 | + /// <returns>IEnumerator of resources</returns> |
| 61 | + IEnumerator IEnumerable.GetEnumerator() |
| 62 | + { |
| 63 | + return GetEnumerator(); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments