C
C#2y ago
GameShark

❔ Changing object property not limited to scope?

So here in UserManager there is a method:
public virtual async Task UpdateNormalizedUserNameAsync(TUser user)
{
var normalizedName = NormalizeName(await GetUserNameAsync(user).ConfigureAwait(false));
normalizedName = ProtectPersonalData(normalizedName);
await Store.SetNormalizedUserNameAsync(user, normalizedName, CancellationToken).ConfigureAwait(false);
}
public virtual async Task UpdateNormalizedUserNameAsync(TUser user)
{
var normalizedName = NormalizeName(await GetUserNameAsync(user).ConfigureAwait(false));
normalizedName = ProtectPersonalData(normalizedName);
await Store.SetNormalizedUserNameAsync(user, normalizedName, CancellationToken).ConfigureAwait(false);
}
And then in the Store.SetNormalizedUserNamyAsync method:
public virtual Task SetNormalizedUserNameAsync(TUser user, string? normalizedName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
user.NormalizedUserName = normalizedName;
return Task.CompletedTask;
}
public virtual Task SetNormalizedUserNameAsync(TUser user, string? normalizedName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
user.NormalizedUserName = normalizedName;
return Task.CompletedTask;
}
There is no ref keyword before TUser. So doesn't that mean setting the user.NormalizedUserName is useless since the change will not be affected by whatever calls it?
5 Replies
Angius
Angius2y ago
Is TUser a reference type?
GameShark
GameShark2y ago
Wouldn't you have to use the ref keyword for it to be a reference type?
Angius
Angius2y ago
No Classes and records are reference types Structs are value types
GameShark
GameShark2y ago
Huh. I always thought passing an object into aa method creates a copy of the obj. TIL. Thanks.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.