-
Notifications
You must be signed in to change notification settings - Fork 557
/
UriSchemeKeyedCollection.cs
87 lines (73 loc) · 2.81 KB
/
UriSchemeKeyedCollection.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
namespace System.ServiceModel
{
public class UriSchemeKeyedCollection : SynchronizedKeyedCollection<string, Uri>
{
internal UriSchemeKeyedCollection(object syncRoot)
: base(syncRoot)
{
}
public UriSchemeKeyedCollection(params Uri[] addresses)
{
if (addresses == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addresses));
}
for (int i = 0; i < addresses.Length; i++)
{
Add(addresses[i]);
}
}
protected override string GetKeyForItem(Uri item)
{
return item.Scheme;
}
protected override void InsertItem(int index, Uri item)
{
ValidateBaseAddress(item, "item");
if (Contains(item.Scheme))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("item", SRP.Format(SRP.BaseAddressDuplicateScheme, item.Scheme));
}
base.InsertItem(index, item);
}
protected override void SetItem(int index, Uri item)
{
ValidateBaseAddress(item, "item");
if (this[index].Scheme != item.Scheme)
{
if (Contains(item.Scheme))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("item", SRP.Format(SRP.BaseAddressDuplicateScheme, item.Scheme));
}
}
base.SetItem(index, item);
}
internal static void ValidateBaseAddress(Uri uri, string argumentName)
{
if (uri == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(argumentName);
}
if (!uri.IsAbsoluteUri)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SRP.BaseAddressMustBeAbsolute);
}
if (!string.IsNullOrEmpty(uri.UserInfo))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SRP.BaseAddressCannotHaveUserInfo);
}
if (!string.IsNullOrEmpty(uri.Query))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SRP.BaseAddressCannotHaveQuery);
}
if (!string.IsNullOrEmpty(uri.Fragment))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SRP.BaseAddressCannotHaveFragment);
}
}
}
}