Value semantic extension
-
Value type inheritance
[ValueInherit]
[ValueBase]
Specify base type field
namespace TheNamespace; public enum FooEnum { A, B } public record struct Foo<T>() { public int Field1 = 0; public static int Field2 = 0; public readonly int Field3 = 0; public readonly ref readonly int Prop1 => throw new NotImplementedException(); public int this[int a] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public readonly object? Some(FooEnum a = FooEnum.A) => throw new NotImplementedException(); public void Some<A, B>(ref int a) => throw new NotImplementedException(); } [ValueInherit] public partial record struct Bar<T>() { [ValueBase] private Foo<T> _base = new(); }
Generate output:
TheNamespace.Bar[T].ValueInherit.g.cs
// <auto-generated/> #nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace TheNamespace { public partial record struct Bar<T> { #region Field Forwards /// <inheritdoc cref="TheNamespace.Foo{T}.Field1"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] public ref int Field1 { [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => ref _base.Field1; } /// <inheritdoc cref="TheNamespace.Foo{T}.Field2"/> [global::Coplt.ValueSemantics.Metas.Forward] public static ref int Field2 { [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => ref TheNamespace.Foo<T>.Field2; } /// <inheritdoc cref="TheNamespace.Foo{T}.Field3"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] public readonly ref readonly int Field3 { [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => ref _base.Field3; } #endregion // Field Forwards #region Property Forwards /// <inheritdoc cref="TheNamespace.Foo{T}.Prop1"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] public readonly ref readonly int Prop1 { [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => ref _base.Prop1; } /// <inheritdoc cref="TheNamespace.Foo{T}[int]"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] public int this[int a] { [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get => _base[a]; [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] set => _base[a] = value; } #endregion // Property Forwards #region Method Forwards /// <inheritdoc cref="TheNamespace.Foo{T}.Some(TheNamespace.FooEnum)"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public readonly object? Some(TheNamespace.FooEnum a = (TheNamespace.FooEnum)0) => _base.Some(a); /// <inheritdoc cref="TheNamespace.Foo{T}.Some{A, B}(ref int)"/> [global::Coplt.ValueSemantics.Metas.Forward] [global::System.Diagnostics.CodeAnalysis.UnscopedRef] [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Some<A, B>(ref int a) => _base.Some<A, B>(ref a); #endregion // Method Forwards } } // namespace TheNamespace