/
UniqueKeyDefinition.cs
57 lines (50 loc) · 1.8 KB
/
UniqueKeyDefinition.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
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Fluent
{
using System;
using System.Collections.ObjectModel;
/// <summary>
/// <see cref="UniqueKeyPolicy"/> fluent definition.
/// </summary>
public class UniqueKeyDefinition
{
private readonly Collection<string> paths = new Collection<string>();
private readonly ContainerBuilder parent;
private readonly Action<UniqueKey> attachCallback;
internal UniqueKeyDefinition(
ContainerBuilder parent,
Action<UniqueKey> attachCallback)
{
this.parent = parent;
this.attachCallback = attachCallback;
}
/// <summary>
/// Adds a path to the current <see cref="UniqueKeyDefinition"/>.
/// </summary>
/// <param name="path">Path for the property to add to the current <see cref="UniqueKeyDefinition"/>. Example: /property</param>
/// <returns>An instance of the current <see cref="UniqueKeyDefinition"/>.</returns>
public UniqueKeyDefinition Path(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
this.paths.Add(path);
return this;
}
/// <summary>
/// Applies the current definition to the parent.
/// </summary>
/// <returns>An instance of the parent.</returns>
public ContainerBuilder Attach()
{
this.attachCallback(new UniqueKey()
{
Paths = this.paths
});
return this.parent;
}
}
}