Install
| Product | Versions |
|---|---|
| .NET |
README
Meziantou.Framework.StronglyTypedId.Interfaces
Optional interfaces for strongly-typed IDs generated by the Meziantou.Framework.StronglyTypedId source generator.
Overview
This library provides two interfaces that can be implemented by strongly-typed IDs to enable polymorphic access to the underlying value:
IStronglyTypedId- Non-generic interface for accessing the value as a stringIStronglyTypedId<T>- Generic interface for accessing the strongly-typed value
Usage
When you use the StronglyTypedId source generator, the generated types automatically implement these interfaces if this package is referenced in your project.
using Meziantou.Framework;
using Meziantou.Framework.Annotations;
[StronglyTypedId(typeof(int))]
public partial struct UserId { }
// The generated type implements IStronglyTypedId and IStronglyTypedId<int>
var userId = UserId.FromInt32(42);
// Access via interface
IStronglyTypedId stronglyTypedId = userId;
Console.WriteLine(stronglyTypedId.ValueAsString); // "42"
// Access via generic interface
IStronglyTypedId<int> typedId = userId;
Console.WriteLine(typedId.Value); // 42
Interfaces
IStronglyTypedId
Provides access to the underlying value as a string.
public interface IStronglyTypedId
{
string ValueAsString { get; }
Type UnderlyingType { get; }
}
IStronglyTypedId<T>
Provides strongly-typed access to the underlying value.
public interface IStronglyTypedId<T> : IStronglyTypedId
{
T Value { get; }
}
When to Use
These interfaces are useful when:
- You need to work with strongly-typed IDs polymorphically
- You want to write generic code that works with any strongly-typed ID
- You need to access the underlying value without knowing the specific ID type at compile time
Related Packages
- Meziantou.Framework.StronglyTypedId - Source generator for creating strongly-typed IDs
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.