ShadowCode.PropertyMapping
1.0.1
dotnet add package ShadowCode.PropertyMapping --version 1.0.1
NuGet\Install-Package ShadowCode.PropertyMapping -Version 1.0.1
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="ShadowCode.PropertyMapping" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ShadowCode.PropertyMapping" Version="1.0.1" />
<PackageReference Include="ShadowCode.PropertyMapping"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ShadowCode.PropertyMapping --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ShadowCode.PropertyMapping, 1.0.1"
#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.
#:package ShadowCode.PropertyMapping@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ShadowCode.PropertyMapping&version=1.0.1
#tool nuget:?package=ShadowCode.PropertyMapping&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ShadowCode.PropertyMapping
为类型生成Get和Set委托映射
基本设置
nuget
PM
PM> Install-Package ShadowCode.PropertyMapping
Project
<ItemGroup>
<PackageReference Include="ShadowCode.PropertyMapping" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
global using
global using ShadowCode;
基础用法
类型定义
namespace Sample;
// 标记特性PropertyMappingAttribute
[PropertyMapping]
internal class Data
{
public int Value { get; set; }
}
生成代码
namespace ShadowCode.PropertyMapping.g.Sample;
partial class g_Data
{
static g_Data()
{
GetMaps = new Dictionary<string, Func<Data, dynamic?>>
{
["Value"] = Get_Value,
};
SetMaps = new Dictionary<string, Action<Data, dynamic?>>
{
["Value"] = Set_Value,
};
}
public static IReadOnlyDictionary<string, Action<Data, dynamic?>> SetMaps { get; }
public static IReadOnlyDictionary<string, Func<Data, dynamic?>> GetMaps { get; }
public static dynamic? Get_Value(Data obj) => obj.Value;
public static void Set_Value(Data obj, dynamic? value) =>
obj.Value = value is null ? default(int) : value;
}
外部程序集类型
使用泛型参数指定外部程序集
// 在任意类型上标记
[PropertyMapping<DateTime>]
class xxxx{ }
生成代码
namespace ShadowCode.PropertyMapping.g.System;
partial class g_DateTime
{
static g_DateTime()
{
GetMaps = new Dictionary<string, Func<DateTime, dynamic?>>
{
["Date"] = Get_Date,
["Day"] = Get_Day,
...
};
SetMaps = new Dictionary<string, Action<DateTime, dynamic?>>
{};
}
public static IReadOnlyDictionary<string, Action<DateTime, dynamic?>> SetMaps { get; }
public static IReadOnlyDictionary<string, Func<DateTime, dynamic?>> GetMaps { get; }
public static dynamic? Get_Date(DateTime obj) => obj.Date;
public static dynamic? Get_Day(DateTime obj) => obj.Day;
public static ...
}
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.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.