Skip to content

Commit cf9a4f1

Browse files
committed
Fixup test
1 parent d1dc9e3 commit cf9a4f1

5 files changed

+30
-17
lines changed

src/Components/Components/src/Microsoft.AspNetCore.Components.WarningSuppressions.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,11 @@
7979
<property name="Scope">member</property>
8080
<property name="Target">M:Microsoft.AspNetCore.Components.LayoutView.&lt;&gt;c__DisplayClass13_0.&lt;WrapInLayout&gt;g__Render|0(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder)</property>
8181
</attribute>
82+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
83+
<argument>ILLink</argument>
84+
<argument>IL2080</argument>
85+
<property name="Scope">member</property>
86+
<property name="Target">M:Microsoft.AspNetCore.Components.Reflection.MemberAssignment.&lt;GetPropertiesIncludingInherited&gt;d__0.MoveNext</property>
87+
</attribute>
8288
</assembly>
83-
</linker>
89+
</linker>

src/Components/Components/src/Reflection/MemberAssignment.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics.CodeAnalysis;
7-
using System.Linq;
87
using System.Reflection;
98
using static Microsoft.AspNetCore.Internal.LinkerFlags;
109

@@ -16,13 +15,13 @@ public static IEnumerable<PropertyInfo> GetPropertiesIncludingInherited(
1615
[DynamicallyAccessedMembers(Component)] Type type,
1716
BindingFlags bindingFlags)
1817
{
19-
var dictionary = new Dictionary<string, List<PropertyInfo>>();
18+
var dictionary = new Dictionary<string, List<PropertyInfo>>(StringComparer.Ordinal);
2019

2120
Type? currentType = type;
2221

2322
while (currentType != null)
2423
{
25-
var properties = currentType.GetProperties(bindingFlags | BindingFlags.DeclaredOnly);
24+
var properties = currentType.GetProperties(bindingFlags | BindingFlags.DeclaredOnly);
2625
foreach (var property in properties)
2726
{
2827
if (!dictionary.TryGetValue(property.Name, out var others))
@@ -31,7 +30,7 @@ public static IEnumerable<PropertyInfo> GetPropertiesIncludingInherited(
3130
dictionary.Add(property.Name, others);
3231
}
3332

34-
if (others.Any(other => other.GetMethod?.GetBaseDefinition() == property.GetMethod?.GetBaseDefinition()))
33+
if (others.Exists(other => other.GetMethod?.GetBaseDefinition() == property.GetMethod?.GetBaseDefinition()))
3534
{
3635
// This is an inheritance case. We can safely ignore the value of property since
3736
// we have seen a more derived value.
@@ -44,7 +43,13 @@ public static IEnumerable<PropertyInfo> GetPropertiesIncludingInherited(
4443
currentType = currentType.BaseType;
4544
}
4645

47-
return dictionary.Values.SelectMany(p => p);
46+
foreach (var list in dictionary.Values)
47+
{
48+
foreach (var property in list)
49+
{
50+
yield return property;
51+
}
52+
}
4853
}
4954
}
5055
}

src/Components/Components/test/ParameterViewTest.Assignment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public void SettingCaptureUnmatchedValuesParameterExplicitlyAndImplicitly_Revers
357357
Assert.Equal(
358358
$"The property '{nameof(HasCaptureUnmatchedValuesProperty.CaptureUnmatchedValues)}' on component type '{typeof(HasCaptureUnmatchedValuesProperty).FullName}' cannot be set explicitly when " +
359359
$"also used to capture unmatched values. Unmatched values:" + Environment.NewLine +
360-
$"test1" + Environment.NewLine +
361-
$"test2",
360+
$"test2" + Environment.NewLine +
361+
$"test1",
362362
ex.Message);
363363
}
364364

src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.ComponentModel.DataAnnotations;
88
using System.Diagnostics.CodeAnalysis;
9-
using System.Linq;
109
using System.Reflection;
1110

1211
namespace Microsoft.AspNetCore.Components.Forms
@@ -58,15 +57,16 @@ private static void ValidateModel(EditContext editContext, ValidationMessageStor
5857
continue;
5958
}
6059

61-
if (!validationResult.MemberNames.Any())
60+
var hasMembers = false;
61+
foreach (var memberName in validationResult.MemberNames)
6262
{
63-
messages.Add(new FieldIdentifier(editContext.Model, fieldName: string.Empty), validationResult.ErrorMessage!);
64-
continue;
63+
hasMembers = true;
64+
messages.Add(editContext.Field(memberName), validationResult.ErrorMessage!);
6565
}
6666

67-
foreach (var memberName in validationResult.MemberNames)
67+
if (!hasMembers)
6868
{
69-
messages.Add(editContext.Field(memberName), validationResult.ErrorMessage!);
69+
messages.Add(new FieldIdentifier(editContext.Model, fieldName: string.Empty), validationResult.ErrorMessage!);
7070
}
7171
}
7272

@@ -86,7 +86,10 @@ private static void ValidateField(EditContext editContext, ValidationMessageStor
8686

8787
Validator.TryValidateProperty(propertyValue, validationContext, results);
8888
messages.Clear(fieldIdentifier);
89-
messages.Add(fieldIdentifier, results.Select(result => result.ErrorMessage!));
89+
for (var i = 0; i < results.Count; i++)
90+
{
91+
messages.Add(fieldIdentifier, results[i].ErrorMessage!);
92+
}
9093

9194
// We have to notify even if there were no messages before and are still no messages now,
9295
// because the "state" that changed might be the completion of some async validation task

src/Components/Forms/src/ValidationMessageStore.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using System.Linq.Expressions;
87

98
namespace Microsoft.AspNetCore.Components.Forms
@@ -65,7 +64,7 @@ public void Add(Expression<Func<object>> accessor, IEnumerable<string> messages)
6564
/// <param name="fieldIdentifier">The identifier for the field.</param>
6665
/// <returns>The validation messages for the specified field within this <see cref="ValidationMessageStore"/>.</returns>
6766
public IEnumerable<string> this[FieldIdentifier fieldIdentifier]
68-
=> _messages.TryGetValue(fieldIdentifier, out var messages) ? messages : Enumerable.Empty<string>();
67+
=> _messages.TryGetValue(fieldIdentifier, out var messages) ? messages : Array.Empty<string>();
6968

7069
/// <summary>
7170
/// Gets the validation messages within this <see cref="ValidationMessageStore"/> for the specified field.

0 commit comments

Comments
 (0)