Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 78 additions & 78 deletions AzureSearchToolkit.IntegrationTest/App_Data/listings-mocked.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion AzureSearchToolkit.IntegrationTest/Models/Listing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using Microsoft.Spatial;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
Expand Down Expand Up @@ -36,7 +37,7 @@ class Listing : IEquatable<Listing>
[IsFilterable]
public string[] Tags { get; set; }

[IsFilterable, IsSortable]
[IsFilterable, IsSortable, JsonProperty("placeCoordinates")]
public GeographyPoint Place { get; set; }

public Listing() { }
Expand Down
7 changes: 6 additions & 1 deletion AzureSearchToolkit/Mapping/AzureSearchMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ private Dictionary<string, string> GetMappedPropertiesForType(Type sourceType)

foreach (var property in sourceType.GetProperties())
{
if (camelCasePropertyAttribute != null)
var jsonPropertyAttribute = property.GetCustomAttribute<JsonPropertyAttribute>();
if(jsonPropertyAttribute != null)
{
mappedPropertiesCache[sourceType].Add(jsonPropertyAttribute.PropertyName, property.Name);
}
else if (camelCasePropertyAttribute != null)
{
var camelCasePropertyName = MappingHelper.ToCamelCase(property.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal static Tuple<Expression, ParameterExpression> Rebind(Type sourceType, I

protected virtual Expression VisitAzureSearchField(MemberExpression m)
{
return Expression.Convert(Expression.Property(BindingParameter, "Item", Expression.Constant(m.Member.Name.ToLowerInvariant())), m.Type);
return Expression.Convert(Expression.Property(BindingParameter, "Item", Expression.Constant(NameHelper.GetMemberName(m.Member))), m.Type);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using AzureSearchToolkit.Mapping;
using AzureSearchToolkit.Utilities;
using Microsoft.Azure.Search.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

namespace AzureSearchToolkit.Request.Visitors
{
Expand Down Expand Up @@ -51,7 +51,7 @@ Expression VisitFieldSelection(MemberExpression m)
{
var member = base.VisitAzureSearchField(m);

fieldNames.Add(m.Member.Name.ToLowerInvariant());
fieldNames.Add(NameHelper.GetMemberName(m.Member));

return member;
}
Expand Down
29 changes: 29 additions & 0 deletions AzureSearchToolkit/Utilities/NameHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using AzureSearchToolkit.Mapping;
using Microsoft.Azure.Search.Models;
using Newtonsoft.Json;
using System.Reflection;

namespace AzureSearchToolkit.Utilities
{
static class NameHelper
{
public static string GetMemberName(MemberInfo member)
{
var jsonPropertyAttribute = member.GetCustomAttribute<JsonPropertyAttribute>();

if (jsonPropertyAttribute != null)
{
return jsonPropertyAttribute.PropertyName;
}

var camelCaseAttribute = member.DeclaringType.GetCustomAttribute<SerializePropertyNamesAsCamelCaseAttribute>();

if (camelCaseAttribute != null)
{
return MappingHelper.ToCamelCase(member.Name);
}

return member.Name;
}
}
}