DamnSmallMapper 0.2.0
See the version list below for details.
dotnet add package DamnSmallMapper --version 0.2.0
NuGet\Install-Package DamnSmallMapper -Version 0.2.0
<PackageReference Include="DamnSmallMapper" Version="0.2.0" />
<PackageVersion Include="DamnSmallMapper" Version="0.2.0" />
<PackageReference Include="DamnSmallMapper" />
paket add DamnSmallMapper --version 0.2.0
#r "nuget: DamnSmallMapper, 0.2.0"
#:package DamnSmallMapper@0.2.0
#addin nuget:?package=DamnSmallMapper&version=0.2.0
#tool nuget:?package=DamnSmallMapper&version=0.2.0
DamnSmallMapper
How to use
Basically you can use
var foo = new Foo();
foo.MapFrom(bar);
That's it! Now foo object contains values from object bar. It map properties with the same name ignoring case and type.
How to ignore properties
There are two different ways to mark property as ignored
- DoNotMapAttribute
- IgnoreProps function
First, you can mark property by DoNotMapAttribute in target-class
public TargetClass
{
[DoNotMap]
public string IgnoredInTarget { get; set; }
}
or in source-class
public SourceClass
{
[DoNotMap]
public string IgnoredInSource { get; set; }
}
And the second option is IgnoreProps function in BasicMapProfile (check Map profiles section below) or using ignoreProps argument in MapFrom function
foo.MapFrom(bar, nameof(Bar.IgnoredProp));
Map profiles
It's possible to create your own map profile.
public class CustomMapProfile : BasicMapProfile
{
protected override void DefineMapping(object source, object target)
{
IgnoreProps(nameof(Foo.IgnoredProperty));
(target as Foo)!.IgnoredProperty = "Another value";
base.DefineMapping(source, target);
}
}
And use it in your code
var customMapProfile = new CustomMapProfile();
foo.MapFrom(bar, customMapProfile);
Samples
You can find useful parts of the code in test-project
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | 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.1
- 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.