-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUrn.linq
58 lines (44 loc) · 1.13 KB
/
Urn.linq
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
<Query Kind="Program" />
void Main()
{
string request = "abcde";
var response = Key.Create<string>(request);
response.Dump();
}
// Define other methods and classes here
public class Key
{
public static string FieldSeparator = ":";
public static string Create<T>(string field) => Create(typeof(T), field);
public static string Create<T>(params string[] fields) => Create(typeof(T), fields);
public static string Create(Type type, params string[] fields)
{
if (type == null)
{
throw new ArgumentNullException($"Argument {nameof(type)} cannot be null");
}
if (fields == null)
{
throw new ArgumentNullException($"Argument {nameof(fields)} cannot be null");
}
string urn = type.Name;
foreach (string field in fields)
{
urn += FieldSeparator;
urn += field;
}
return urn;
}
public static string Create(Type type, string field)
{
if (type == null)
{
throw new ArgumentNullException($"Argument {nameof(type)} cannot be null");
}
if (field == null)
{
throw new ArgumentNullException($"Argument {nameof(field)} cannot be null");
}
return $"{type.Name}{FieldSeparator}{field}";
}
}