Skip to main content

MakeInterface.Generator by Frederik

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: MakeInterface.Generator

Generates interfaces for classes

Author: Frederik

NuGet: https://www.nuget.org/packages/MakeInterface.Generator/

You can find more details at https://github.com/Frederik91/MakeInterface

Source : https://github.com/Frederik91/MakeInterface

Original Readme

note

MakeInterface

Creates an interface of a class using source generator

.NET

Usage

Add the attribute to the class you want to generate the interface for

[GenerateInterface]
public class MyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
}

The generated interface will then be generated as IMyClass.g.cs

public interface IMyClass
{
string MyProperty { get; set; }
void MyMethod();
}

You can then implement the interface in your class

public class MyClass : IMyClass
{
public string MyProperty { get; set; }
public void MyMethod() { }
}

Installation

Install the NuGet package MakeInterface

You can either create the attribute yourself or use the one provided in the package MakeInterface.Contracts

License

MIT

About

note

Generating interface from class definition

How to use

Example ( source csproj, source files )

This is the CSharp Project that references MakeInterface.Generator

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MakeInterface.Contracts" Version="0.4.0" />
<PackageReference Include="MakeInterface.Generator" Version="0.4.0" OutputItemType="Analyzer" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

using MakeInterface.Contracts.Attributes;

// <auto-generated/>
#pragma warning disable
#nullable enable
namespace Class2Interface;
public partial interface IPerson
{
int ID { get; set; }

string FirstName { get; set; }

string LastName { get; set; }

string Name { get; }

string FullName();
}

Usefull

Download Example (.NET C# )

Share MakeInterface.Generator

https://ignatandrei.github.io/RSCG_Examples/v2/docs/MakeInterface.Generator

In the same category (Interface) - 9 other generators

Biwen.AutoClassGen

CopyCat

Farskeptic.AutoCompose

Matryoshki

Minerals.AutoInterfaces

NetAutomaticInterface

ProxyGen

Roozie.AutoInterface

RSCG_Static