< Summary

Class:Azure.Search.Documents.Indexes.Models.SearchFieldTemplate
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Indexes\Models\SearchFieldTemplate.cs
Covered lines:11
Uncovered lines:0
Coverable lines:11
Total lines:60
Line coverage:100% (11 of 11)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_Name()-100%100%
get_Type()-100%100%
op_Implicit(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Indexes\Models\SearchFieldTemplate.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Core;
 6
 7namespace Azure.Search.Documents.Indexes.Models
 8{
 9    /// <summary>
 10    /// Base field type for helper classes to more easily create a <see cref="SearchIndex"/>.
 11    /// </summary>
 12    public abstract class SearchFieldTemplate
 13    {
 14        /// <summary>
 15        /// Initializes a new instance of the <see cref="SearchFieldTemplate"/> class.
 16        /// </summary>
 17        /// <param name="name">The name of the field, which must be unique within the index or parent field.</param>
 18        /// <param name="type">The data type of the field.</param>
 19        /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
 20        /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
 1954121        private protected SearchFieldTemplate(string name, SearchFieldDataType type)
 22        {
 1954123            Argument.AssertNotNullOrEmpty(name, nameof(name));
 24
 1954125            Name = name;
 1954126            Type = type;
 1954127        }
 28
 29        /// <summary>
 30        /// Gets the name of the field.
 31        /// </summary>
 1954132        public string Name { get; }
 33
 34        /// <summary>
 35        /// Gets the data type of the field.
 36        /// </summary>
 1954137        public SearchFieldDataType Type { get; }
 38
 39        /// <summary>
 40        /// Persists class-specific properties into the given <see cref="SearchField"/>.
 41        /// </summary>
 42        /// <param name="field">The <see cref="SearchField"/> into which properties are persisted.</param>
 43        private protected abstract void Save(SearchField field);
 44
 45        /// <summary>
 46        /// Casts a <see cref="SearchFieldTemplate"/> or derivative to a <see cref="SearchField"/>.
 47        /// </summary>
 48        /// <param name="value">The <see cref="SearchFieldTemplate"/> or derivative to cast.</param>
 49        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
 50        public static implicit operator SearchField(SearchFieldTemplate value)
 51        {
 1954152            Argument.AssertNotNull(value, nameof(value));
 53
 1954154            SearchField field = new SearchField(value.Name, value.Type);
 1954155            value.Save(field);
 56
 1954157            return field;
 58        }
 59    }
 60}