-
Notifications
You must be signed in to change notification settings - Fork 81
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
Hierarchical IDs? #82
Comments
You can already do this, I'm doing something similar in one of my private projects. Using The only drawback would be you'd get a constructor that would allow you to create an instance with a raw string value however my PR #79 would resolve this by being able to disable the generation of the constructor. |
Sorry for the delay with this 😳. I'm currently working on a big redesign of the library in this PR: The main idea is to make the library much more maintainable while also giving people a mechanism to customise the generated IDs as much as they like. This will make it easy to make changes like this 🙂 |
For what its worth, I ended up implementing this in my project, but I also needed to have some limited inheritance. To reuse the example I gave above, suppose I had public readonly record struct StoreId(int Id)
{
public string ToString() => Id.ToString();
}
public readonly record struct GroceryStoreId(int Id) : StoreId(Id) // Uh oh! Can't inherit from a struct!!
{
} So, to handle inheritance, I needed to use a reference type. But, I did not want to incur the cost of instantiation each time. Additionally, I would want to be able to use Looking back, I knew that Then, I have some abstract base classes:
Then, derived classes would simply need to add a public static It works well for me. Other people might like the same approach. If you're interested, I can add the |
In one of my applications, I have a set of hierarchical IDs.
Take, for example, if I wanted to have a way to uniquely identify an aisle in a store. Without
StronglyTypedId
, I might do this:Each level of the hierarchy provides a different context. A
SectionId
with an integer value of 1, inStoreId
1 is not the same as aSectionId
with an integer value of 1, inStoreId
2It would be nice if I could do something similar with
StronglyTypedId
.The text was updated successfully, but these errors were encountered: