/
SyndicationLink.cs
162 lines (132 loc) · 4.73 KB
/
SyndicationLink.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Xml;
namespace System.ServiceModel.Syndication
{
// NOTE: This class implements Clone so if you add any members, please update the copy ctor
public class SyndicationLink : IExtensibleSyndicationObject
{
private ExtensibleSyndicationObject _extensions;
private long _length;
public SyndicationLink(Uri uri) : this(uri, null, null, null, 0)
{
}
public SyndicationLink(Uri uri, string relationshipType, string title, string mediaType, long length)
{
if (length < 0)
{
throw new ArgumentOutOfRangeException(nameof(length));
}
BaseUri = null;
Uri = uri;
Title = title;
RelationshipType = relationshipType;
MediaType = mediaType;
_length = length;
}
public SyndicationLink() : this(null, null, null, null, 0)
{
}
protected SyndicationLink(SyndicationLink source)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
_length = source._length;
MediaType = source.MediaType;
RelationshipType = source.RelationshipType;
Title = source.Title;
BaseUri = source.BaseUri;
Uri = source.Uri;
_extensions = source._extensions.Clone();
}
public Dictionary<XmlQualifiedName, string> AttributeExtensions => _extensions.AttributeExtensions;
public Uri BaseUri { get; set; }
public SyndicationElementExtensionCollection ElementExtensions => _extensions.ElementExtensions;
public long Length
{
get => _length;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
_length = value;
}
}
public string MediaType { get; set; }
public string RelationshipType { get; set; }
public string Title { get; set; }
public Uri Uri { get; set; }
public static SyndicationLink CreateAlternateLink(Uri uri)
{
return CreateAlternateLink(uri, null);
}
public static SyndicationLink CreateAlternateLink(Uri uri, string mediaType)
{
return new SyndicationLink(uri, Atom10Constants.AlternateTag, null, mediaType, 0);
}
public static SyndicationLink CreateMediaEnclosureLink(Uri uri, string mediaType, long length)
{
return new SyndicationLink(uri, Rss20Constants.EnclosureTag, null, mediaType, length);
}
public static SyndicationLink CreateSelfLink(Uri uri)
{
return CreateSelfLink(uri, null);
}
public static SyndicationLink CreateSelfLink(Uri uri, string mediaType)
{
return new SyndicationLink(uri, Atom10Constants.SelfTag, null, mediaType, 0);
}
public virtual SyndicationLink Clone() => new SyndicationLink(this);
public Uri GetAbsoluteUri()
{
if (Uri != null)
{
if (Uri.IsAbsoluteUri)
{
return Uri;
}
else if (BaseUri != null)
{
return new Uri(BaseUri, Uri);
}
else
{
return null;
}
}
else
{
return null;
}
}
protected internal virtual bool TryParseAttribute(string name, string ns, string value, string version)
{
return false;
}
protected internal virtual bool TryParseElement(XmlReader reader, string version)
{
return false;
}
protected internal virtual void WriteAttributeExtensions(XmlWriter writer, string version)
{
_extensions.WriteAttributeExtensions(writer);
}
protected internal virtual void WriteElementExtensions(XmlWriter writer, string version)
{
_extensions.WriteElementExtensions(writer);
}
internal void LoadElementExtensions(XmlReader readerOverUnparsedExtensions, int maxExtensionSize)
{
_extensions.LoadElementExtensions(readerOverUnparsedExtensions, maxExtensionSize);
}
internal void LoadElementExtensions(XmlBuffer buffer)
{
_extensions.LoadElementExtensions(buffer);
}
}
}