-
Notifications
You must be signed in to change notification settings - Fork 88
Generate explicit cast operators #206
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Coming from the strong type generator I wrote a few years ago using T4, I'm missing the functionality of using explicit casts.
The existing methods, e.g. InternalUserId.From(42) do their job, but migrating would be painful, as the current code base accross a hundred solutions all use explicit casts for conversion into strong types: var userId = (InternalUserId)42;.
The linked T4 template generates two explicit operators (types in code just as example) that allow easy yet explicit conversion only:
/// <summary>
/// Converts the weak type into a <see cref="InternalUserId"/> instance.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>A new instance of the strong type.</returns>
[ExcludeFromCodeCoverage]
public static explicit operator InternalUserId(System.Int32 value)
{
return new InternalUserId(value);
}
/// <summary>
/// Converts the strong type into a <see cref="System.Int32"/> value.
/// </summary>
/// <param name="value">The instance to convert.</param>
/// <returns>The converted value.</returns>
[ExcludeFromCodeCoverage]
public static explicit operator System.Int32(InternalUserId value)
{
return value.V;
}Without much overhead, this would allow for even easier user of value objects.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request