© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo ago•
12 replies
Victor H

Generic static factories

Hello. I have the following interface:

public interface IStronglyTypedId<TValue, out TSelf>
    where TSelf : IStronglyTypedId<TValue, TSelf>
{
    TValue Value { get; }
    static abstract TSelf From(TValue value);
}
public interface IStronglyTypedId<TValue, out TSelf>
    where TSelf : IStronglyTypedId<TValue, TSelf>
{
    TValue Value { get; }
    static abstract TSelf From(TValue value);
}


This works well but I want to have a specific type of strongly typed id's of type
AggregateId
AggregateId
which must have an underlying backing type of
Guid
Guid
, especially a version 7 guid. So basically how can I have default implementations for abstract records?

I tried this but infinite recursion.
public abstract record AggregateId<TId>(Guid Value) : IStronglyTypedId<Guid, TId>
    where TId : IStronglyTypedId<Guid, TSelf>
{
    public static TSelf From(Guid value) => TSelf.From(value); // <- infinite recursion
}
public abstract record AggregateId<TId>(Guid Value) : IStronglyTypedId<Guid, TId>
    where TId : IStronglyTypedId<Guid, TSelf>
{
    public static TSelf From(Guid value) => TSelf.From(value); // <- infinite recursion
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Is there some generic type for factories in asp net core?
C#CC# / help
4y ago
Ommit generic for static abstract conversion methods
C#CC# / help
9mo ago
❔ How do generic parameters with static classes work?
C#CC# / help
4y ago
Calling a static abstract method without a generic type [Answered]
C#CC# / help
4y ago