RSCG – Minerals.AutoInterfaces

 
 

name Minerals.AutoInterfaces
nuget https://www.nuget.org/packages/Minerals.AutoInterfaces/
link https://github.com/SzymonHalucha/Minerals.AutoInterfaces
author Szymon HaƂucha

Generating interface from class

 

This is how you can use Minerals.AutoInterfaces .

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>

	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>

	<ItemGroup>
	  <PackageReference Include="Minerals.AutoInterfaces" Version="0.1.5" />
	</ItemGroup>
</Project>


The code that you will use is


// See https://aka.ms/new-console-template for more information
using Class2Interface;

Console.WriteLine("Hello, World!");
IPerson person=new Person();
person.FirstName="Andrei";
person.LastName="Ignat";
Console.WriteLine(person.FullName());


namespace Class2Interface;
[Minerals.AutoInterfaces.GenerateInterface("IPerson")]
public partial class Person:IPerson
{
    public int ID { get; set; }
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
    public string Name
    {
        get
        {
            return $"{FirstName} {LastName}";
        }
    }
    public string FullName()=>$"{FirstName} {LastName}";
}


 

The code that is generated is

// <auto-generated>
// This code was generated by a tool.
// Name: Minerals.AutoInterfaces
// Version: 0.1.5+54d6efe308ef06f041fc9b5d9285caeecef3e7c4
// </auto-generated>
#pragma warning disable CS9113
namespace Minerals.AutoInterfaces
{
    [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 GenerateInterfaceAttribute : global::System.Attribute
    {
        public GenerateInterfaceAttribute(string customName = "")
        {
        }
    }
}
#pragma warning restore CS9113
// <auto-generated>
// This code was generated by a tool.
// Name: Minerals.AutoInterfaces
// Version: 0.1.5+54d6efe308ef06f041fc9b5d9285caeecef3e7c4
// </auto-generated>
namespace Class2Interface
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    public interface IPerson
    {
        int ID { get; set; }
        string? FirstName { get; set; }
        string? LastName { get; set; }
        string Name { get; }
        string FullName();
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Minerals.AutoInterfaces