RSCG – Minerals.AutoMixins
name | Minerals.AutoMixins |
nuget | https://www.nuget.org/packages/Minerals.AutoMixins/ |
link | https://github.com/SzymonHalucha/Minerals.AutoMixins |
author | Szymon Halucha |
Generate Mixin from another classes
This is how you can use Minerals.AutoMixins .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="Minerals.AutoMixins" Version="0.2.1" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
using DemoMixin; Person person = new Person { Name = "Andrei Ignat" }; person.LogName();
namespace DemoMixin; [Minerals.AutoMixins.AddMixin(typeof(LogData))] internal partial class Person { public string Name { get; set; } public void LogName() => Log(Name); }
namespace DemoMixin; [Minerals.AutoMixins.GenerateMixin] internal class LogData { public void Log(string data) => Console.WriteLine(data); }
The code that is generated is
// <auto-generated> // This code was generated by a tool. // Name: Minerals.AutoMixins // Version: 0.2.1+6c5634e46b130effbe00bd9d3f94459f1dbb2e85 // </auto-generated> namespace DemoMixin { [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Runtime.CompilerServices.CompilerGenerated] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] internal partial class Person { // MixinType: LogData public void Log(string data) => Console.WriteLine(data); } }
// <auto-generated> // This code was generated by a tool. // Name: Minerals.AutoMixins // Version: 0.2.1+6c5634e46b130effbe00bd9d3f94459f1dbb2e85 // </auto-generated> #pragma warning disable CS9113 namespace Minerals.AutoMixins { [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Runtime.CompilerServices.CompilerGenerated] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] public sealed class AddMixinAttribute : global::System.Attribute { public AddMixinAttribute(params global::System.Type[] mixins) { } } } #pragma warning restore CS9113
// <auto-generated> // This code was generated by a tool. // Name: Minerals.AutoMixins // Version: 0.2.1+6c5634e46b130effbe00bd9d3f94459f1dbb2e85 // </auto-generated> namespace Minerals.AutoMixins { [global::System.Diagnostics.DebuggerNonUserCode] [global::System.Runtime.CompilerServices.CompilerGenerated] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] public sealed class GenerateMixinAttribute : global::System.Attribute { } }
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Minerals.AutoMixins
Leave a Reply