Skip to content

Examples

beakona edited this page Dec 1, 2023 · 3 revisions

Simple scenario

Manually written source:

public interface IPrintable
{
}

[BeaKona.GenerateAutoAs]
public partial class Person : IPrintable
{
}

Auto-generated accompanying source:

partial class Person
{
   public IPrintable AsPrintable() => this;
}

Method accessibility

Manually written source:

internal interface IPrintable
{
}

[BeaKona.GenerateAutoAs]
public partial class Person : IPrintable
{
}

Auto-generated accompanying source:

partial class Person
{
   internal IPrintable AsPrintable() => this;
}

Interface hierarchy

Manually written source:

public interface IBase
{
}

public interface IPrintable : IBase
{
}

[BeaKona.GenerateAutoAs(EntireInterfaceHierarchy = true)]
public partial class Person : IPrintable
{
}

Auto-generated accompanying source:

partial class Person
{
   public IPrintable AsPrintable() => this;
   public IBase AsBase() => this;
}

Omit System.* interfaces

Manually written source:

public interface IPrintable
{
}

[BeaKona.GenerateAutoAs(SkipSystemInterfaces = true)]
public partial class Person : IPrintable, IEnumerable
{
}

Auto-generated accompanying source:

partial class Person
{
   public IPrintable AsPrintable() => this;
}

Clone this wiki locally