From 1d4c2cece3a4137d3315f435f662e502d35a47c5 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 10 Feb 2017 11:01:00 -0800 Subject: [PATCH 1/2] Fix the sdk version in this branch --- global.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/global.json b/global.json index fad3dfeab0..ebe9c99ebe 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,6 @@ { - "projects": ["src", "test/WebSites", "samples"] + "projects": ["src", "test/WebSites", "samples"], + "sdk": { + "version": "1.0.0-preview2-003154" + } } From fa710e60f8f7155338c19c531b8f9363d3a19e55 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 10 Feb 2017 11:03:13 -0800 Subject: [PATCH 2/2] Do not name a `ModelType` variable "Type" - #5595 - enhance the `StartsWith()` check to look at what comes after --- .../Internal/ExpressionHelper.cs | 9 ++++++--- .../Internal/ExpressionHelperTest.cs | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs index 414ff0038c..8a246beb2c 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs @@ -101,11 +101,14 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe // If parts start with "model", then strip that part away. if (part == null || part.NodeType != ExpressionType.Parameter) { + const string dotModel = ".model"; + var dotModelLength = dotModel.Length; + var text = builder.ToString(); - if (text.StartsWith(".model", StringComparison.OrdinalIgnoreCase)) + if (text.StartsWith(dotModel, StringComparison.OrdinalIgnoreCase) && + (text.Length == dotModelLength || text[dotModelLength] == '.' || text[dotModelLength] == '[')) { - // 6 is the length of the string ".model". - builder.Remove(0, 6); + builder.Remove(0, dotModelLength); } } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs index 36ce863aff..aab65d2639 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs @@ -21,6 +21,9 @@ public static IEnumerable ExpressionAndTexts var Model = new TestModel(); var key = "TestModel"; var myModels = new List(); + var models = new List(); + var modelTest = new TestModel(); + var modelType = typeof(TestModel); return new TheoryData { @@ -56,6 +59,18 @@ public static IEnumerable ExpressionAndTexts (Expression>)(m => Model), string.Empty }, + { + (Expression>)(model => models[0].SelectedCategory.CategoryId), + "models[0].SelectedCategory.CategoryId" + }, + { + (Expression>)(model => modelTest.Name), + "modelTest.Name" + }, + { + (Expression>)(model => modelType), + "modelType" + }, { (Expression, Category>>)(model => model[2].SelectedCategory), "[2].SelectedCategory" @@ -157,8 +172,8 @@ public static IEnumerable EquivalentExpressions (Expression>)(m => value) }, { - // These two expressions are not actually equivalent. However ExpressionHelper returns - // string.Empty for these two expressions and hence they are considered as equivalent by the + // These two expressions are not actually equivalent. However ExpressionHelper returns + // string.Empty for these two expressions and hence they are considered as equivalent by the // cache. (Expression>)(m => Model), (Expression>)(m => m)