-
Notifications
You must be signed in to change notification settings - Fork 2
/
Operator.cs
106 lines (93 loc) · 3.43 KB
/
Operator.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
using System;
namespace UriTemplateString.Spec
{
/// <summary>
/// Represents a URI Template expression operator
/// </summary>
public struct Operator
{
/// <summary>
/// Gets the query continuation operator.
/// </summary>
public static readonly Operator QueryContinuation = new Operator('&');
/// <summary>
/// Gets the path parameter operator.
/// </summary>
public static readonly Operator PathParameter = new Operator(';');
/// <summary>
/// Gets the path segment operator.
/// </summary>
public static readonly Operator PathSegment = new Operator('/');
/// <summary>
/// Gets the dot prefix operator
/// </summary>
public static readonly Operator DotPrefixedName = new Operator('.');
/// <summary>
/// Gets the hash fragment operator.
/// </summary>
public static readonly Operator HashFragment = new Operator('#');
/// <summary>
/// Gets the reserved character string operator.
/// </summary>
public static readonly Operator ReservedCharacterString = new Operator('+');
/// <summary>
/// Gets the query string operator.
/// </summary>
public static readonly Operator QueryComponent = new Operator('?');
private readonly char value;
private Operator(char value)
{
this.value = value;
}
/// <summary>
/// Creates an oeprator from the string representation
/// </summary>
/// <param name="operatorCharacter">A string containing the operator character (excluding values reserved in RFC6570 for future use)</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// When the parameter is not a single-character string containing one of valid operators
/// </exception>
public static Operator FromString(string operatorCharacter)
{
if (operatorCharacter.Length == 0)
{
return default(Operator);
}
switch (operatorCharacter)
{
case "?":
return Operator.QueryComponent;
case "+":
return Operator.ReservedCharacterString;
case "#":
return Operator.HashFragment;
case ".":
return Operator.DotPrefixedName;
case "/":
return Operator.PathSegment;
case ";":
return Operator.PathParameter;
case "&":
return Operator.QueryContinuation;
case "!":
case "=":
case ",":
case "@":
case "|":
throw new NotImplementedException($"The operator character {operatorCharacter} is reserved for future extensions and not currently supported");
default:
throw new ArgumentOutOfRangeException(nameof(operatorCharacter));
}
}
/// <summary>
/// Returns a <see cref="string" /> that represents this instance.
/// </summary>
public override string ToString()
{
if (this.value == default(char))
{
return string.Empty;
}
return this.value.ToString();
}
}
}