Use ordinal comparisons in `ExpressionTextCache`

- #6349
- C# field and property names are case-sensitive
  - it's not important (where this cache is used) that HTML field names are case-insenstive
This commit is contained in:
Doug Bunting 2017-06-28 15:41:44 -07:00
parent 17f6b17a6d
commit 293ac81fe1
2 changed files with 49 additions and 2 deletions

View File

@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
return true;
}
if (!string.Equals(memberName1, memberName2, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(memberName1, memberName2, StringComparison.Ordinal))
{
return false;
}
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
break;
}
hashCodeCombiner.Add(memberName, StringComparer.OrdinalIgnoreCase);
hashCodeCombiner.Add(memberName, StringComparer.Ordinal);
expression = memberExpression.Expression;
}
else

View File

@ -39,6 +39,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId),
"SelectedCategory.CategoryId"
},
{
(Expression<Func<LowerModel, int>>)(testModel => testModel.selectedcategory.CategoryId),
"selectedcategory.CategoryId"
},
{
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory),
"SelectedCategory.CategoryName.MainCategory"
@ -71,6 +75,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<IList<TestModel>, Category>>)(model => model[i].SelectedCategory),
"[3].SelectedCategory"
},
{
(Expression<Func<IList<LowerModel>, Category>>)(model => model[i].selectedcategory),
"[3].selectedcategory"
},
{
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
"[TestModel].SelectedCategory.CategoryName.MainCategory"
@ -87,10 +95,18 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<IList<TestModel>, int>>)(model => model[2].PreferredCategories[i].CategoryId),
"[2].PreferredCategories[3].CategoryId"
},
{
(Expression<Func<IList<LowerModel>, int>>)(model => model[2].preferredcategories[i].CategoryId),
"[2].preferredcategories[3].CategoryId"
},
{
(Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Name),
"Name"
},
{
(Expression<Func<IList<LowerModel>, string>>)(model => model.FirstOrDefault().name),
"name"
},
{
(Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Model),
"Model"
@ -285,10 +301,22 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory),
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName)
},
{
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName),
(Expression<Func<LowerModel, CategoryName>>)(model => model.selectedcategory.CategoryName)
},
{
(Expression<Func<TestModel, string>>)(model => model.Model),
(Expression<Func<TestModel, string>>)(model => model.Name)
},
{
(Expression<Func<TestModel, string>>)(model => model.Model),
(Expression<Func<LowerModel, string>>)(model => model.model)
},
{
(Expression<Func<TestModel, string>>)(model => model.Name),
(Expression<Func<LowerModel, string>>)(model => model.name)
},
{
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName),
(Expression<Func<TestModel, string>>)(model => value)
@ -301,6 +329,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<IList<TestModel>, Category>>)(model => model[2].SelectedCategory),
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory)
},
{
(Expression<Func<IList<TestModel>, Category>>)(model => model[2].SelectedCategory),
(Expression<Func<IList<LowerModel>, Category>>)(model => model[2].selectedcategory)
},
{
(Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId),
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory)
@ -309,6 +341,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory)
},
{
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
(Expression<Func<IDictionary<string, LowerModel>, string>>)(model => model[key].selectedcategory.CategoryName.MainCategory)
},
{
(Expression<Func<TestModel, string>>)(m => Model),
(Expression<Func<TestModel, string>>)(m => m.Model)
@ -408,6 +444,17 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
public IList<Category> PreferredCategories { get; set; }
}
private class LowerModel
{
public string name { get; set; }
public string model { get; set; }
public Category selectedcategory { get; set; }
public IList<Category> preferredcategories { get; set; }
}
private class Category
{
public int CategoryId { get; set; }