Skip to content

Commit

Permalink
Add support for normalizing user names.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewKing committed Nov 8, 2023
1 parent 99c5bdf commit d871335
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/DeviceId/DeviceIdBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,24 @@ public static DeviceIdBuilder UseFormatter(this DeviceIdBuilder builder, IDevice
/// <returns>The <see cref="DeviceIdBuilder"/> instance.</returns>
public static DeviceIdBuilder AddUserName(this DeviceIdBuilder builder)
{
return builder.AddComponent("UserName", new DeviceIdComponent(Environment.UserName));
// Default to false for backwards compatibility. May consider changing this to true in the next major version.

return AddUserName(builder, false);
}

/// <summary>
/// Adds the current user name to the device identifier.
/// </summary>
/// <param name="builder">The <see cref="DeviceIdBuilder"/> to add the component to.</param>
/// <param name="normalize">A value determining whether the user name should be normalized or not.</param>
/// <returns>The <see cref="DeviceIdBuilder"/> instance.</returns>
public static DeviceIdBuilder AddUserName(this DeviceIdBuilder builder, bool normalize)
{
var userName = normalize
? Environment.UserName?.ToLowerInvariant()
: Environment.UserName;

return builder.AddComponent("UserName", new DeviceIdComponent(userName));
}

/// <summary>
Expand Down

0 comments on commit d871335

Please sign in to comment.