mapperly
A .NET source generator for generating object mappings. No runtime reflection.
- 4.2k
- C#
- Apache-2.0
- 13 h ago

Automatic implemention of stronly typed IDs via record structs with compile-time feature auto-detection
Repo devlooped/StructId, read from GitHub 1 min ago. devlooped has not joined Take My Repo.
devlooped/StructId is a public repo on GitHub by devlooped. Automatic implemention of stronly typed IDs via record structs with compile-time feature auto-detection. It declares the MIT license on GitHub. It is written mainly in C#, has 42 stars and last changed on 2026-11-13. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-19.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
An opinionated strongly-typed ID library that uses readonly record struct in C# for
maximum performance, minimal memory allocation typed identifiers.
public readonly partial record struct UserId : IStructId<Guid>; // String-based ID public readonly partial record struct ProductId : IStructId;
Unlike other such libraries for .NET, StructId introduces several unique features:
IParsable<T>/ISpanParsable<T> for parsing from strings.TSelf.New(TValue value) factory
method and proper type constraint (via a provided INewable<TSelf, TValue> interface).After installing the StructId package, the project
(with a direct reference to the StructId package) will contain the main interfaces
IStruct (for string-typed IDs) and IStructId<TValue>.
NOTE: the package only needs to be installed in the top-level project in your solution, since analyzers/generators will automatically propagate to referencing projects.
The package is a development dependency, meaning it will not add any run-time dependencies to your project (or package if you publish one that uses struct ids).
You can simply declare a new ID type by implementing IStructId<TValue>:
public readonly partial record struct UserId : IStructId<Guid>;
If the declaration is missing partial, readonly or record struct, a codefix will
be offered to correct it.
The relevant constructor and Value property will be generated for you, as well as
as a few other common interfaces, such as IComparable<T>, IParsable<TSelf>, etc.
If you want to customize the primary constructor (i.e. to add custom attributes), you can provide it yourself too:
public readonly partial record struct ProductId(int Value) : IStructId<int>;
It must contain a single parameter named Value (and codefixes will offer to rename or
remove it if you don't need it anymore).
If you are using EF Core, the package will automatically generate the necessary value converters,
as well as an UseStructId extension method for DbContextOptionsBuilder to set them up:
var options = new DbContextOptionsBuilder<Context>() .UseSqlite("Data Source=ef.db") .UseStructId() .Options; using var context = new Context(options); // access your entities using struct ids
Alternatively, you can also invoke that method in the OnConfiguring method of your context:
protected override void OnConfiguring(DbContextOptionsBuilder builder) => builder.UseStructId();
In addition to the natively supported primitive types, any other types that implement IParsable<T>
and IFormattable get automatic support by persisting as strings. This means that you can,
for example, use Ulid out of the box without any further
configuration or customization (since it implements both interfaces).
Additionally, the UseStructId will pick up any custom ValueConverter<TModel,TProvider>
you may add to your project and register them too for convenience.
If you are using Dapper, the package will automatically generate required SqlMapper.TypeHandler<T>
for your ID types. The UseStructId extension method for IDbConnection can be used to register
them as needed:
using var connection = new SqliteConnection("Data Source=sqlite.db") connection.UseStructId(); connection.Open();
The value types Guid, int, long and string have built-in support, as well as
any other types that implement IParsable<T> and IFormattable (by persisting them
as strings). This means that you can, for example, use Ulid
out of the box without any further configuration or customization (since it implements
both interfaces).
Additionally, the UseStructId will pick up any custom Dapper.SqlMapper.TypeHandler<T>
you may add to your project and register them too for convenience.
Since Ulid implements IParsable<T> and IFormattable,
it is supported out of the box without any further configuration or customization with both
Dapper and EF Core.
In addition to the necessary converter/handler registration, the package will also generate
a New() (parameterless) factory method for struct ids using Ulid as the value type, which
in turn will use Ulid.NewUlid() to generate a new value. This mirrors the behavior
generated for Guid-based struct ids.
public readonly partial record struct ProductId : IStructId<Ulid>; public record Product(ProductId Id, string Name); // Create a new product with a new Ulid-based id var productId = ProductId.New(); // ๐ equivalent to: new ProductId(Ulid.NewUlid()) var product = new Product(productId, "Product"); // Seed data connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", new Product(ProductId.New(), "Product1")); connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", product); connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", new Product(ProductId.New(), "Product2")); // showcase we can query by the underlying ulid var saved1 = connection.QueryFirst<Product>("SELECT * FROM Products WHERE Id = @Id", new { Id = productId }); // showcase we can query by the ulid-based struct id var saved2 = connection.QueryFirst<Product>("SELECT * FROM Products WHERE Id = @Id", new { Id = new ProductId(productId) });
Virtually all the built-in interfaces and implementations are generated using the same compiled templates mechanism available to you. Templates are regular C# files in your project with a few constraints. Here's an example from the built-in ones:
using System; using StructId; [TStructId] file partial record struct TSelf(IUtf8SpanFormattable Value) : IUtf8SpanFormattable { /// <inheritdoc/> public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) => ((IUtf8SpanFormattable)Value).TryFormat(utf8Destination, out bytesWritten, format, provider); }
This type is considered a template because it's marked with the [TStructId] attribute.
This introduces some restrictions that are enfored by an analyzer:
partial record struct since it will complement a partial declaration
of that type by the user (i.e. partial record struct PersonId : IStructId<Guid>;)Value of that type.TSelf.The template itself can introduce arbitrary code that will be emitted for each matching
struct id (i.e. all struct ids whose value type implements IUtf8SpanFormattable in this case).
In this example, the template simply offers a pass-through implementation of the IUtf8SpanFormattable
value.
As another example, imagine you have some standardized way of treating IDs in your application,
by providing an interface for them, which applies to all Guid-based IDs:
public interface IId { Guid Id { get; } }
You can now create a template that will automatically provide this interface for all struct
ids that use Guid as their value type as follows:
[TStructId] file partial record struct TSelf(Guid Value) : IId { public Guid Id => Value; }
Another example of a built-in template that applies to a single type of TValue is
the following:
using StructId; [TStructId] file partial record struct TSelf(string Value) { public static implicit operator string(TSelf id) => id.Value; public static explicit operator TSelf(string value) => new(value); }
This template is a proper C# compilation unit, so you can use any C# feature that your project supports, since its output will also be emitted via a source generator in the same project for matching struct ids.
In the case of a struct id defined as follows:
public partial record struct PersonId : IStructId<Guid>;
The template will be applied automatically and result in a partial declaration like:
partial record struct PersonId : IId { public Guid Id => Value; }
Things to note at template expansion time:
[TStructId] attribute is removed from the generated type automatically.TSelf type is replaced with the actual name of the struct id.You can also constrain the type of TValue the template applies to by using using
the special name TValue for the primary constructor parameter type, as in the following
example from the implicit conversion template:
using StructId; [TStructId] file partial record struct TSelf(TValue Value) { public static implicit operator TValue(TSelf id) => id.Value; public static explicit operator TSelf(TValue value) => new(value); } // This will be removed when applying the template to each user-defined struct id. file record struct TValue;
The TValue is subsequently defined as a file-local type where you can
specify any interfaces it implements. If no constraints need to apply to
TValue, you can just leave the declaration empty, meaning "any value type".
NOTE: The type of declaration (struct, class, record, etc.) of
TValueis not checked, since in many cases you'd end up having to create two versions of the same template, one for structs and another for strings, since they are not value types and have no common declaration type.
Here's another example from the built-in templates that uses this technique to
apply to all struct ids whose TValue implements IComparable<TValue>:
using System; using StructId; [TStructId] file partial record struct TSelf(TValue Value) : IComparable<TSelf> { /// <inheritdoc/> public int CompareTo(TSelf other) => ((IComparable<TValue>)Value).CompareTo(other.Value); /// <inheritdoc/> public static bool operator <(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) < 0; /// <inheritdoc/> public static bool operator <=(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) <= 0; /// <inheritdoc/> public static bool operator >(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) > 0; /// <inheritdoc/> public static bool operator >=(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) >= 0; } // This will be removed when applying the template to each user-defined struct id. file record struct TValue : IComparable<TValue> { public int CompareTo(TValue other) => throw new NotImplementedException(); }
This automatically covers not only all built-in value types, but also any custom types that implement the interface, making the code generation much more flexible and powerful.
NOTE: if you need to exclude just the string type from applying to the
TValue, you can use the inline comment/*!string*/in the primary constructor parameter type, as inTSelf(/*!string*/ TValue Value).
In addition to constraining on the TValue type, you can also constrain on the
the struct id/TSelf itself by declaring the inheritance requirements in a partial
class of TSelf in the template. For example, the following (built-in) template
ensures it's only applied to struct ids whose TValue is Ulid
and implement INewable<TSelf, Ulid>. This is useful in this case since the given
interface constraint allows us to use the TSelf.New(Ulid) static interface
factory method and have it recognized by the C# compiler as valid code as part of the
implementation of introduced parameterless New() factory method provided by the template:
[TStructId] file partial record struct TSelf(Ulid Value) { public static TSelf New() => new(Ulid.NewUlid()); } // This will be removed when applying the template to each user-defined struct id. file partial record struct TSelf : INewable<TSelf, Ulid> { public static TSelf New(Ulid value) => throw new NotImplementedException(); }
NOTE: the built-in templates will always emit an implementation of
INewable<TSelf, TValue>for all struct ids.
Here you can see that the constraint that the value type must be Ulid is enforced by
the TValue constructor parameter type, while the interface constraint in the partial
declaration enforces inheritance from INewable<TSelf, Ulid>. Since this part of
the partial declaration is removed, there is no need to provide an actual implementation
for the constrain interface(s), just the signature is enough. But the partial declaration
providing the interface constraint is necessary for the C# compiler to recognize the
line with public static TSelf New() => new(Ulid.NewUlid()); as valid.
We also produce CI packages from branches and pull requests so you can dogfood builds as quickly as they are produced.
The CI feed is https://pkg.kzu.app/index.json.
The versioning scheme for packages is:
[NUMBER][BRANCH].[COMMITS]To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.
To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.
devlooped/StructId is a public repo on GitHub by devlooped. Automatic implemention of stronly typed IDs via record structs with compile-time feature auto-detection.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-13. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
PolySharp provides generated, source-only polyfills for C# language features, to easily use all runtime-agnostic features downlevel. Add a reference, set your C# version to latest and have fun! ๐

A high performance implementation of Mediator pattern in .NET using source generators.
A list of C# Source Generators (not necessarily awesome) and associated resources: articles, talks, demos.


Expose project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.

Create, edit and run multiple C# top-level programs in the same project by just selecting the startup program from the start button.


Take My Repo has not tested this on your machine. Requirements come from the project's own documentation.