Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Search] .NET SDK v9.0, supporting API version 2019-05-06 #6009

Merged
merged 7 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/SDKs/Search/DataPlane/AzSearch.DataPlane.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net452;netstandard1.4</TargetFrameworks>
<TargetFrameworks>$(SdkTargetFx)</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public static void IfArgument(bool isInvalid, string paramName, string message =
}
}

/// <summary>
/// Throws ArgumentOutOfRangeException with the given parameter name and optional message if the given Boolean
/// value is true.
/// </summary>
/// <param name="isInvalid">The flag to test. This method throws if it's true and does nothing if
/// it's false.</param>
/// <param name="paramName">The name of the parameter being validated. This is passed to the
/// ArgumentOutOfRangeException constructor.</param>
/// <param name="message">An optional error message to include in the ArgumentOutOfRangeException. The default
/// message is "Argument out of range."</param>
public static void IfArgumentOutOfRange(bool isInvalid, string paramName, string message = null)
{
if (isInvalid)
{
message = message ?? "Argument out of range.";
throw new ArgumentOutOfRangeException(paramName, message);
}
}

/// <summary>
/// Throws ArgumentNullException with the given parameter name and optional message if the given
/// reference is null.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace Microsoft.Azure.Search.Models
using System.Reflection;

/// <summary>
/// Indicates that the public properties of a model class should be serialized as camel-case in order to match
/// Indicates that the public properties of a model type should be serialized as camel-case in order to match
/// the field names of an Azure Search index.
/// </summary>
/// <remarks>
/// Classes without this attribute are expected to have property names that exactly match their corresponding
/// fields names in Azure Search. Otherwise, it would not be possible to use instances of the class to populate
/// Types without this attribute are expected to have property names that exactly match their corresponding
/// fields names in Azure Search. Otherwise, it would not be possible to use instances of the type to populate
/// the index.
/// </remarks>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
public class SerializePropertyNamesAsCamelCaseAttribute : Attribute
{
/// <summary>
Expand All @@ -26,8 +26,16 @@ public class SerializePropertyNamesAsCamelCaseAttribute : Attribute
/// <typeparam name="T">The type to test.</typeparam>
/// <returns>true if the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute,
/// false otherwise.</returns>
public static bool IsDefinedOnType<T>() =>
typeof(T)
public static bool IsDefinedOnType<T>() => IsDefinedOnType(typeof(T));

/// <summary>
/// Indicates whether the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute.
/// </summary>
/// <param name="modelType">The type to test.</param>
/// <returns>true if the given type is annotated with SerializePropertyNamesAsCamelCaseAttribute,
/// false otherwise.</returns>
public static bool IsDefinedOnType(Type modelType) =>
modelType
.GetTypeInfo()
.GetCustomAttributes(typeof(SerializePropertyNamesAsCamelCaseAttribute), inherit: true)
.Any();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,44 @@
namespace Microsoft.Azure.Search.Serialization
{
using System;
using System.Linq;
using System.Reflection;
using Common;
using Models;
using Newtonsoft.Json;

/// <summary>
/// Delegate type for a factory method that creates or looks up an ExtensibleEnum instance from a given string.
/// </summary>
/// <typeparam name="T">The type of ExtensibleEnum returned.</typeparam>
/// <param name="name">The enum value to look up or create.</param>
/// <returns>An instance of type T.</returns>
public delegate T ExtensibleEnumValueFactory<T>(string name) where T : ExtensibleEnum<T>;

/// <summary>
/// Serializes and deserializes "extensible enums" to and from JSON. Extensible enums are like enumerations in
/// that they have well-known values, but they are extensible with new values and the values are based on strings
/// instead of integers.
/// </summary>
public class ExtensibleEnumConverter<T> : JsonConverter where T : ExtensibleEnum<T>
public class ExtensibleEnumConverter<T> : JsonConverter
{
private ExtensibleEnumValueFactory<T> _enumValueFactory;
private readonly Func<string, T> _enumValueFactory;

/// <summary>
/// Initializes a new instance of the ExtensibleEnumConverter class.
/// </summary>
public ExtensibleEnumConverter() : this("Create") { }

/// <summary>
/// Initializes a new instance of the ExtensibleEnumConverter class.
/// </summary>
/// <param name="factoryMethodName">
/// The name of a public static method that creates an instance of type T given a string value; Default is
/// "Create".
/// </param>
public ExtensibleEnumConverter(string factoryMethodName)
public ExtensibleEnumConverter()
{
Throw.IfArgumentNull(factoryMethodName, "factoryMethodName");
bool TakesSingleStringParameter(ConstructorInfo ctor)
{
ParameterInfo[] parameters = ctor.GetParameters();
if (parameters.Length == 1)
{
return parameters[0].ParameterType == typeof(string);
}

MethodInfo method = typeof(T).GetTypeInfo().GetDeclaredMethod(factoryMethodName);
return false;
}

const string MessageFormat =
"No method named '{0}' could be found that is convertible to ExtensibleEnumValueFactory<{1}>.";
ConstructorInfo fromStringCtor = typeof(T).GetTypeInfo().DeclaredConstructors.FirstOrDefault(TakesSingleStringParameter);

Throw.IfArgument(
method == null,
"factoryMethodName",
String.Format(MessageFormat, factoryMethodName, typeof(T).Name));
fromStringCtor == null,
typeof(T).Name,
$"No constructor taking a string parameter could be found for type '{typeof(T)}'.");

_enumValueFactory =
(ExtensibleEnumValueFactory<T>)method.CreateDelegate(typeof(ExtensibleEnumValueFactory<T>));
_enumValueFactory = str => (T)fromStringCtor.Invoke(new[] { str });
}

/// <summary>
Expand Down
Loading