/
ComplexField.cs
56 lines (51 loc) · 2.5 KB
/
ComplexField.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
namespace Azure.Search.Documents.Indexes.Models
{
/// <summary>
/// A complex field or collection of complex fields that contain child fields.
/// Child fields may be <see cref="SimpleField"/> or <see cref="ComplexField"/>.
/// </summary>
public class ComplexField : SearchFieldTemplate
{
/// <summary>
/// Initializes a new instance of the <see cref="ComplexField"/> class.
/// </summary>
/// <param name="name">The name of the field, which must be unique within the index or parent field.</param>
/// <param name="collection">Whether the field is a collection of strings.</param>
/// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
public ComplexField(string name, bool collection = false) : base(name, collection ? SearchFieldDataType.Collection(SearchFieldDataType.Complex) : SearchFieldDataType.Complex)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ComplexField"/> class.
/// </summary>
/// <param name="name">The name of the field, which must be unique within the index or parent field.</param>
/// <param name="type">The data type of the field.</param>
/// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
/// <remarks>
/// This is used internally by FieldBuilder to avoid detecting if the type is a collection just
/// to return the same type we started with.
/// </remarks>
internal ComplexField(string name, SearchFieldDataType type) : base(name, type)
{
}
/// <summary>
/// Gets a collection of <see cref="SimpleField"/> or <see cref="ComplexField"/> child fields.
/// </summary>
public IList<SearchFieldTemplate> Fields { get; } = new List<SearchFieldTemplate>();
/// <inheritdoc/>
private protected override void Save(SearchField field)
{
IList<SearchField> fields = field.Fields;
foreach (SearchFieldTemplate child in Fields)
{
fields.Add(child);
}
}
}
}