-
Notifications
You must be signed in to change notification settings - Fork 477
/
SpatialIndexDefinition.cs
83 lines (72 loc) · 2.75 KB
/
SpatialIndexDefinition.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
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Fluent
{
using System;
/// <summary>
/// Spatial index fluent definition.
/// </summary>
/// <seealso cref="SpatialPath"/>
public class SpatialIndexDefinition<T>
{
private readonly SpatialPath spatialSpec = new SpatialPath();
private readonly T parent;
private readonly Action<SpatialPath> attachCallback;
internal SpatialIndexDefinition(
T parent,
Action<SpatialPath> attachCallback)
{
this.parent = parent;
this.attachCallback = attachCallback;
}
/// <summary>
/// Adds a path to the current <see cref="SpatialPath"/> definition.
/// </summary>
/// <param name="path">Property path for the current definition. Example: /property</param>
/// <returns>An instance of the current <see cref="SpatialIndexDefinition{T}"/>.</returns>
public SpatialIndexDefinition<T> Path(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
this.spatialSpec.Path = path;
return this;
}
/// <summary>
/// Add a path to the current <see cref="SpatialPath"/> definition with a particular set of <see cref="SpatialType"/>s.
/// </summary>
/// <param name="path">Property path for the current definition. Example: /property</param>
/// <param name="spatialTypes">Set of <see cref="SpatialType"/> to apply to the path.</param>
/// <returns>An instance of the current <see cref="SpatialIndexDefinition{T}"/>.</returns>
public SpatialIndexDefinition<T> Path(
string path,
params SpatialType[] spatialTypes)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
if (spatialTypes == null)
{
throw new ArgumentNullException(nameof(spatialTypes));
}
this.spatialSpec.Path = path;
foreach (SpatialType spatialType in spatialTypes)
{
this.spatialSpec.SpatialTypes.Add(spatialType);
}
return this;
}
/// <summary>
/// Applies the current definition to the parent.
/// </summary>
/// <returns>An instance of the parent.</returns>
public T Attach()
{
this.attachCallback(this.spatialSpec);
return this.parent;
}
}
}