< Summary

Class:Microsoft.Azure.Search.Models.SerializePropertyNamesAsCamelCaseAttribute
Assembly:Microsoft.Azure.Search.Common
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Common\src\Customizations\Search\Models\SerializePropertyNamesAsCamelCaseAttribute.cs
Covered lines:5
Uncovered lines:0
Coverable lines:5
Total lines:43
Line coverage:100% (5 of 5)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
IsDefinedOnType()-100%100%
IsDefinedOnType(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Common\src\Customizations\Search\Models\SerializePropertyNamesAsCamelCaseAttribute.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.Search.Models
 6{
 7    using System;
 8    using System.Linq;
 9    using System.Reflection;
 10
 11    /// <summary>
 12    /// Indicates that the public properties of a model type should be serialized as camel-case in order to match
 13    /// the field names of a search index.
 14    /// </summary>
 15    /// <remarks>
 16    /// Types without this attribute are expected to have property names that exactly match their corresponding
 17    /// fields names in Azure Cognitive Search. Otherwise, it would not be possible to use instances of the type to popu
 18    /// the index.
 19    /// </remarks>
 20    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
 21    public class SerializePropertyNamesAsCamelCaseAttribute : Attribute
 22    {
 23        /// <summary>
 24        /// Indicates whether the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute.
 25        /// </summary>
 26        /// <typeparam name="T">The type to test.</typeparam>
 27        /// <returns>true if the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute,
 28        /// false otherwise.</returns>
 40629        public static bool IsDefinedOnType<T>() => IsDefinedOnType(typeof(T));
 30
 31        /// <summary>
 32        /// Indicates whether the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute.
 33        /// </summary>
 34        /// <param name="modelType">The type to test.</param>
 35        /// <returns>true if the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute,
 36        /// false otherwise.</returns>
 37        public static bool IsDefinedOnType(Type modelType) =>
 84238            modelType
 84239                .GetTypeInfo()
 84240                .GetCustomAttributes(typeof(SerializePropertyNamesAsCamelCaseAttribute), inherit: true)
 84241                .Any();
 42    }
 43}