https://github.com/simulation-tree/types
Source generated type metadata available at runtime
https://github.com/simulation-tree/types
csharp dotnet
Last synced: 5 months ago
JSON representation
Source generated type metadata available at runtime
- Host: GitHub
- URL: https://github.com/simulation-tree/types
- Owner: simulation-tree
- License: mit
- Created: 2025-01-15T02:06:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-24T03:03:04.000Z (9 months ago)
- Last Synced: 2025-09-24T05:16:29.634Z (9 months ago)
- Topics: csharp, dotnet
- Language: C#
- Homepage:
- Size: 161 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Types
[](https://github.com/simulation-tree/types/actions/workflows/test.yml)
Assists programming with value types in C#.
### Initializing
Before types are interacted/accessed, the `MetadataRegistry` must be initialized
by registering the types and interfaces in use:
### Type layouts
These store metadata about what fields are found on a type:
```cs
namespace Example
{
public struct Apple
{
public byte first;
public ushort second;
public Item item;
}
public struct Item
{
public uint id;
}
}
TypeMetadata type = TypeMetadata.Get();
Assert.That(type.FullName.ToString(), Is.EqualTo("Example.Apple"));
Assert.That(type.Size, Is.EqualTo(7));
ReadOnlySpan fields = type.Fields;
Assert.That(fields.Length, Is.EqualTo(3));
Assert.That(fields[0].Name.ToString(), Is.EqualTo("first"));
Assert.That(fields[1].Name.ToString(), Is.EqualTo("second"));
Assert.That(fields[2].Name.ToString(), Is.EqualTo("item"));
Assert.That(fields[2].type, Is.EqualTo(TypeMetadata.Get()));
```
### Type banks
Type banks are generated for every project that references this library.
They contain code that registers declared types:
```cs
MetadataRegistry.Load();
public readonly struct CustomTypeBank : ITypeBank
{
void ITypeBank.Load(Register register)
{
register.Invoke();
}
}
```
### Type registry loaders
These are also generated like type banks. But differ in that they're only
generated for projects with an entry point (a `static void Main()` method).
They load all type banks found in the project:
```cs
MetadataRegistryLoader.Load();
```