Tortuga.Shipwright 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tortuga.Shipwright --version 0.4.0                
NuGet\Install-Package Tortuga.Shipwright -Version 0.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tortuga.Shipwright" Version="0.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tortuga.Shipwright --version 0.4.0                
#r "nuget: Tortuga.Shipwright, 0.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tortuga.Shipwright as a Cake Addin
#addin nuget:?package=Tortuga.Shipwright&version=0.4.0

// Install Tortuga.Shipwright as a Cake Tool
#tool nuget:?package=Tortuga.Shipwright&version=0.4.0                

Tortuga Shipwright

Installation

To register the Source Generator, add the following to your project file.


<ItemGroup>
	<PackageReference Include="Tortuga.Shipwright" Version="0.1.0" />
</ItemGroup>

<PropertyGroup>
	<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
	<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
	
	<Compile Remove="$(CompilerGeneratedFilesOutputPath)/*/**/*.cs" />
</ItemGroup>

The EmitCompilerGeneratedFiles setting is not required, but it does make trouble-shooting easier. Check `Show All Files" in Visual Studio to see the generated files.

Trait Engine

Terminology

  • Trait: A set of methods and properties being injected into a container class.
  • Container: The class that contains one or more traits.

Basic Pattern

The trait needs no special decorations. However, it is advisable to mark it as sealed because inheritance is not supported with traits.

Traits should be marked with the Trait attribute. (This is not currently enforced, but may be in future versions.)

Trait classes may be marked as public or, if in the same assembly, internal.

The container class uses the UseTrait attribute and must be marked partial. For example:

[UseTrait(typeof(MyTrait)]
public partial class MyContiner { ... }

Exposing Members

For a method or property, add the Expose attribute to the member.

[Expose] public int Add(int a, int b) {...}

[Expose] public int CustomerAge {get; set;}

The member being exposed must be visible to the container. This means public or, if in the same assembly, internal.

Non-public Members

To make a exposed member non-public in the container class, set the Accessibility property. For example,

[Expose(Accessibility = Accessibility.Internal)]
public ICacheAdapter Cache { get; set; } = null!;

You may also set an inheritance rule such as override, sealed, or virtual.

[Expose(Inheritance = Inheritance.Override)]
public ConcurrentDictionary<Type, object> ExtensionCache {get => m_ExtensionCache;}
Additional Attributes

The following attributes will be copied from an exposed trait member to the matching container member.

  • EditorBrowsableAttribute
  • ObsoleteAttribute

Accessing the Container

To allow the trait to get a reference to it's container, use the Container attribute.

[Container]
internal IDataSource DataSource { get; set; } = null!;

There is no limit to the number of Container properties in a trait. (Presumably each would request a different interface.)

If RegisterInterface = true is used, then the interface being requeted will be added to the container class. That class will still need to implement the interface.

Callbacks into the container

In lieu of using a container property (see above), a trait can request a specific callback be created in the container.

Define the 'partial' property in the trait as a Func or Action delegate.

[Partial("customerKey,startDate,endDate"] 
public Func<int, DateTime, DateTime, OrderCollection> OnGetOrdersByCustomer {get; set;} = null!;

In the container, the following will be generated.

private partial OrderCollection OnGetOrdersByCustomer(int customerKey, DateTime startDate, DateTime endDate);

The container will then be responsible for implementing the partial method.

Automatically Implementing an Interface

If a trait implements an interface, then it's container will automatically implement it as well. All interface methods and properties will call back to the trait.

The container explicitly implements the interface. Use the Expose attribute on each member if you also want the methods to be marked as public.

Warning: Interfaces with init properties are not supported.

XML Docs

If the trait is in the same project as the container, XML Docs will be automatically included in the generated code.

This requires DocumentationFile to be enabled at the project level.

Shipwright does not currently support XML Docs on traits defined in a different project. (This appears to be a limitation of Roslyn.)

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Tortuga.Shipwright:

Repository Stars
TortugaResearch/Tortuga.Chain
A fluent ORM for .NET
Version Downloads Last updated
0.11.0 263 11/28/2023
0.10.0 162 11/28/2023
0.9.0 2,083 5/10/2022
0.6.0 2,309 3/25/2022
0.5.0 394 3/25/2022
0.4.0 394 3/25/2022
0.3.0 421 3/19/2022
0.2.0 404 3/19/2022
0.1.0 410 3/16/2022