1+ // Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+ namespace Asp . Versioning ;
4+
5+ /// <summary>
6+ /// Represents an API version deprecation policy.
7+ /// </summary>
8+ public class DeprecationPolicy
9+ {
10+ private readonly LinkList links ;
11+
12+ /// <summary>
13+ /// Initializes a new instance of the <see cref="DeprecationPolicy"/> class.
14+ /// </summary>
15+ public DeprecationPolicy ( )
16+ {
17+ links = new DeprecationLinkList ( ) ;
18+ }
19+
20+ /// <summary>
21+ /// Initializes a new instance of the <see cref="DeprecationPolicy"/> class.
22+ /// </summary>
23+ /// <param name="date">The date and time when the API version will be deprecated.</param>
24+ /// <param name="link">The optional link which provides information about the deprecation policy.</param>
25+ public DeprecationPolicy ( DateTimeOffset date , LinkHeaderValue ? link = default )
26+ : this ( )
27+ {
28+ Date = date ;
29+
30+ if ( link is not null )
31+ {
32+ links . Add ( link ) ;
33+ }
34+ }
35+
36+ /// <summary>
37+ /// Initializes a new instance of the <see cref="DeprecationPolicy"/> class.
38+ /// </summary>
39+ /// <param name="link">The link which provides information about the deprecation policy.</param>
40+ public DeprecationPolicy ( LinkHeaderValue link )
41+ : this ( )
42+ {
43+ links . Add ( link ) ;
44+ }
45+
46+ /// <summary>
47+ /// Gets the date and time when the API version will be deprecated.
48+ /// </summary>
49+ /// <value>The date and time when the API version will be deprecated, if any.</value>
50+ public DateTimeOffset ? Date { get ; }
51+
52+ /// <summary>
53+ /// Gets a value indicating whether the deprecation policy has any associated links.
54+ /// </summary>
55+ /// <value>True if the deprecation policy has associated links; otherwise, false.</value>
56+ public bool HasLinks => links . Count > 0 ;
57+
58+ /// <summary>
59+ /// Gets a read-only list of links that provide information about the deprecation policy.
60+ /// </summary>
61+ /// <value>A read-only list of HTTP links.</value>
62+ /// <remarks>If a link is provided, generally only one link is necessary; however, additional
63+ /// links might be provided for different languages or different formats such as a HTML page
64+ /// or a JSON file.</remarks>
65+ public IList < LinkHeaderValue > Links => links ;
66+
67+ internal sealed class DeprecationLinkList : LinkList
68+ {
69+ protected override void EnsureRelationType ( LinkHeaderValue item )
70+ {
71+ if ( ! item . RelationType . Equals ( "deprecation" , StringComparison . OrdinalIgnoreCase ) )
72+ {
73+ throw new ArgumentException ( SR . InvalidDeprecationRelationType , nameof ( item ) ) ;
74+ }
75+ }
76+ }
77+ }
0 commit comments