Skip to content
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

Support generic parameters #740

Open
aradalvand opened this issue Jan 12, 2025 · 0 comments
Open

Support generic parameters #740

aradalvand opened this issue Jan 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@aradalvand
Copy link

aradalvand commented Jan 12, 2025

Describe the feature

I wanted to do this:

/// <summary>
/// Represents a single-iteration BLAKE2d hash.
/// </summary>
/// <typeparam name="TUnderlyingType">
/// The point is to associate the hash with a specific underlying type (normally a domain-specific value object), for documentation purposes, and also to prevent comparing hashes of different underlying types.
/// </typeparam>
[ValueObject<string>]
public readonly partial struct Hash<TUnderlyingType>
{
    /// <summary>
    /// Hashes the provided string with BLAKE2d and returns a <see cref="Hash"/> instance that represents it.
    /// </summary>
    public static Hash<TUnderlyingType> Of(TUnderlyingType input)
    {
        byte[] inputBytes = Encoding.UTF8.GetBytes(input);
        var hash = new byte[64];
        BLAKE2b.ComputeHash(hash, inputBytes);
        return From(Convert.ToBase64String(hash));
    }
}

And realized that Vogen fails to generate code for this declaration. I see no reason why it shouldn't be able to.
The point of the generic argument, in this particular case, is to associate the hash with a specific underlying type (normally a domain-specific value object), for documentation purposes, and also to prevent comparing hashes of different underlying types.

What I want to be able to do is something like this:

[ValueObject<string>]
public readonly partial struct SessionKey; // This being a Vogen type is irrelevant here

// Usage:
Hash<SessionKey> sessionKeyHash = ...;

Please make it so that the source generator just does its thing regardless of whether or not the type has generic parameters. It would enable patterns like this one. I'd appreciate it.

@aradalvand aradalvand added the enhancement New feature or request label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant