T1.SourceGenerator
1.0.2
See the version list below for details.
dotnet add package T1.SourceGenerator --version 1.0.2
NuGet\Install-Package T1.SourceGenerator -Version 1.0.2
<PackageReference Include="T1.SourceGenerator" Version="1.0.2" />
paket add T1.SourceGenerator --version 1.0.2
#r "nuget: T1.SourceGenerator, 1.0.2"
// Install T1.SourceGenerator as a Cake Addin #addin nuget:?package=T1.SourceGenerator&version=1.0.2 // Install T1.SourceGenerator as a Cake Tool #tool nuget:?package=T1.SourceGenerator&version=1.0.2
We provide following features
- Simple Auto Mapping Clone Object Function
- Simple Auto Mapping any interface to WebApi Client Class
How do I get started ?
First, install T1.SourceGenerator nuget package. Attach AutoMapping Attribute on any class.
using T1.SourceGenerator.Attributes;
namespace MyDemoApp;
[AutoMapping(typeof(Employee))]
public class User
{
public string Name { get; set; }
public int Level { get; set; }
public int Vip { get; set; }
}
public class Employee
{
public string Name { get; set; }
public float Level { get; set; }
public int Vip { get; }
}
Then in your application code, execute the mappings:
var source = new User();
var dto = source.ToEmployee();
If you hope change ToEmployee()
method to other extension method, you can do this:
[AutoMapping(typeof(Employee), "CloneToEmployee")]
public class User
{
public string Name { get; set; }
public int Level { get; set; }
public int Vip { get; set; }
}
Then in your application code, execute the mappings:
var source = new User();
var dto = source.CloneToEmployee();
How to get Auto Mapping WebApiClient class ?
[WebApiClient(ClientClassName = "SamApiClient", Namespace = "ConsoleDemoApp")]
public interface IMyApiClient
{
[WebApiClientMethod("mgmt/test1", Method = InvokeMethod.Get, Timeout = "00:00:10")]
void Test(Request1 req);
[WebApiClientMethod("mgmt/test2", Timeout = "00:00:30")]
void Test2();
[WebApiClientMethod("mgmt/test3")]
Response1 Test3();
[WebApiClientMethod("mgmt/test4")]
Response1 Test4(int a);
}
Then in your application code, execute the code:
using T1.SourceGenerator;
var client = new SamApiClient(null);
If you prefer a different namespace ("ConsoleDemoApp"), you can custom it.
[WebApiClient(ClientClassName = "SamApiClient", Namespace = "ConsoleDemoApp")]
public interface IMyApiClient
{
...
}
If you need constructor injection, you can do it like in the following program example.
[WebApiClient(ClientClassName = "SamApiClient", Namespace = "ConsoleDemoApp")]
[WebApiClientConstructorInject(MyConfig), "myConfig")]
public interface IMyApiClient
{
...
}
partial class SamApiClient
{
partial void Initialize()
{
BaseUrl = _myConfig.BaseUrl;
}
}
Even if you need to specify a variable using a special method for constructor injection, you can do it this way.
[WebApiClient(ClientClassName = "SamApiClient", Namespace = "ConsoleDemoApp")]
[WebApiClientConstructorInject(typeof(IOption<MyConfig>), "myConfig", AssignCode="myConfig.Value")]
public interface IMyApiClient
{
...
}
It will produce the following code.
public class SamApiClient
{
public SamApiClient(IHttpClientFactory httpClientFactory,
IOption<MyConfig> myConfig)
{
_myConfig = myConfig.Value;
}
}
Product | Versions 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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
add AutoMapping, WebApi Client