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

View File

@ -39,6 +39,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId), (Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId),
"SelectedCategory.CategoryId" "SelectedCategory.CategoryId"
}, },
{
(Expression<Func<LowerModel, int>>)(testModel => testModel.selectedcategory.CategoryId),
"selectedcategory.CategoryId"
},
{ {
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory), (Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory),
"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), (Expression<Func<IList<TestModel>, Category>>)(model => model[i].SelectedCategory),
"[3].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), (Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
"[TestModel].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), (Expression<Func<IList<TestModel>, int>>)(model => model[2].PreferredCategories[i].CategoryId),
"[2].PreferredCategories[3].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), (Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Name),
"Name" "Name"
}, },
{
(Expression<Func<IList<LowerModel>, string>>)(model => model.FirstOrDefault().name),
"name"
},
{ {
(Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Model), (Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Model),
"Model" "Model"
@ -285,10 +301,22 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory), (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<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.Model),
(Expression<Func<TestModel, string>>)(model => model.Name) (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, CategoryName>>)(model => model.SelectedCategory.CategoryName),
(Expression<Func<TestModel, string>>)(model => value) (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<IList<TestModel>, Category>>)(model => model[2].SelectedCategory),
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory) (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, int>>)(testModel => testModel.SelectedCategory.CategoryId),
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory) (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<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory) (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 => Model),
(Expression<Func<TestModel, string>>)(m => 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; } 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 private class Category
{ {
public int CategoryId { get; set; } public int CategoryId { get; set; }