| | | 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 | | |
| | | 5 | | namespace 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> |
| | 406 | 29 | | 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) => |
| | 842 | 38 | | modelType |
| | 842 | 39 | | .GetTypeInfo() |
| | 842 | 40 | | .GetCustomAttributes(typeof(SerializePropertyNamesAsCamelCaseAttribute), inherit: true) |
| | 842 | 41 | | .Any(); |
| | | 42 | | } |
| | | 43 | | } |