Skip to main content
net10.0net11.0

Provide optional interfaces for the Meziantou.Framework.StronglyTypedId source generator

Published
Jul 5, 2026
3mo ago
Total Downloads
21.4K
21,383

Install

dotnet add package Meziantou.Framework.StronglyTypedId.Interfaces --version 4.0.0
ProductVersions
.NET
net10.0net11.0

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 string
  • IStronglyTypedId<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

Changes from Previous Version

v3.0.1v4.0.0
Removed Frameworks
net8.0net9.0

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.