Hasty Briefsbeta

Bilingual

Comptime – C# meta-programming with compile-time code generation and evaluation

4 months ago
  • #compile-time
  • #dotnet
  • #meta-programming
  • Comptime is a .NET source generator that executes methods at compile time and serializes their results to C# code.
  • Methods marked with [Comptime] are executed during compilation, and their return values are serialized into C# source code.
  • Supports compile-time execution of methods with constant expressions as parameters.
  • Supported return types include primitive types and immutable collections like IReadOnlyList<T> and IReadOnlyDictionary<TKey, TValue>.
  • Arrays are not allowed as return types due to mutability; use IReadOnlyList<T> instead.
  • Supported argument types include literals, collection initializers, expressions, const values, and enum members.
  • Uses C# interceptors to replace method calls with pre-computed values at runtime.
  • Requires .NET 8.0 or later and C# 12 or later for interceptors support.
  • Methods must be static, the containing class must be partial, and arguments must be compile-time constant expressions.
  • Error codes include issues like unsupported return types, compilation emit failures, and method execution failures.
  • Licensed under MIT License.