This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
/
DefaultEndpointDataSource.cs
59 lines (51 loc) · 2.17 KB
/
DefaultEndpointDataSource.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
// 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;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Routing
{
/// <summary>
/// Provides a collection of <see cref="Endpoint"/> instances.
/// </summary>
public sealed class DefaultEndpointDataSource : EndpointDataSource
{
private readonly IReadOnlyList<Endpoint> _endpoints;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultEndpointDataSource" /> class.
/// </summary>
/// <param name="endpoints">The <see cref="Endpoint"/> instances that the data source will return.</param>
public DefaultEndpointDataSource(params Endpoint[] endpoints)
{
if (endpoints == null)
{
throw new ArgumentNullException(nameof(endpoints));
}
_endpoints = (Endpoint[])endpoints.Clone();
}
/// <summary>
/// Initializes a new instance of the <see cref="DefaultEndpointDataSource" /> class.
/// </summary>
/// <param name="endpoints">The <see cref="Endpoint"/> instances that the data source will return.</param>
public DefaultEndpointDataSource(IEnumerable<Endpoint> endpoints)
{
if (endpoints == null)
{
throw new ArgumentNullException(nameof(endpoints));
}
_endpoints = new List<Endpoint>(endpoints);
}
/// <summary>
/// Gets a <see cref="IChangeToken"/> used to signal invalidation of cached <see cref="Endpoint"/>
/// instances.
/// </summary>
/// <returns>The <see cref="IChangeToken"/>.</returns>
public override IChangeToken GetChangeToken() => NullChangeToken.Singleton;
/// <summary>
/// Returns a read-only collection of <see cref="Endpoint"/> instances.
/// </summary>
public override IReadOnlyList<Endpoint> Endpoints => _endpoints;
}
}