-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Use reference equality to compare model instances in EditContext #18172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
de32762
to
dc94234
Compare
@@ -35,7 +38,7 @@ public static FieldIdentifier Create<TField>(Expression<Func<TField>> accessor) | |||
/// <param name="fieldName">The name of the editable field.</param> | |||
public FieldIdentifier(object model, string fieldName) | |||
{ | |||
if (model == null) | |||
if (model is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case a user type has a poorly implemented equality operator.
{ | ||
// Ww want to compare Model instances by reference RuntimeHelpers.GetHashCode returns identical hashes for equal object references which is what we want. | ||
var modelHash = RuntimeHelpers.GetHashCode(Model); | ||
var fieldHash = StringComparer.Ordinal.GetHashCode(FieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use the same Comparer used by Equals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Co-Authored-By: Steve Sanderson <[email protected]>
|
) * Use reference equality to compare model instances in EditContext Fixes #18069
@pranavkm when will this bugfix be available ? |
@aaronhudon the change was ported to the 3.1.3 release as part of #18649. 3.1.3 is scheduled to be released mid-March. |
@pranavkm I have installed the 3.1.3 runtime, and SDK. Unfortunately I'm not seeing a change in behavior (e.g. the bug isn't fixed). Are there any additional project settings that need to be applied? I'm assuming no. |
@aaronhudon are you building a Blazor Server project? |
Yes |
@pranavkm Any updates on this? |
This is fixed in |
So it did not make it in to 3.1.103 ? |
@SteveSandersonMS we ported the fix to 3.1.3. @aaronhudon are you certain you have |
This is what
|
@pranavkm !#%^%^ My project file had Removed, and the fix is fantastic. Thanks again! |
@aaronhudon you might have an older SDK. The version of the .NET runtime for self contained deployment is determined by the version of the SDK. Using 3.1.103 should get you the right version, but you want to make sure you're not using a different preview. |
Fixes #18069