MapOnly 0.2.1

dotnet add package MapOnly --version 0.2.1
NuGet\Install-Package MapOnly -Version 0.2.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="MapOnly" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MapOnly --version 0.2.1
#r "nuget: MapOnly, 0.2.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.
// Install MapOnly as a Cake Addin
#addin nuget:?package=MapOnly&version=0.2.1

// Install MapOnly as a Cake Tool
#tool nuget:?package=MapOnly&version=0.2.1

Welcome to MapOnly Documentation

Introduce

MapOnly is a simple .Net standard library, It uses for convert, mapping from an object to another object. If you want a library lightweight and just for mapping only, MapOnly is a choice for you.

Dependence

.Net Framework > 4.6.1
.Net standard 2.0
.Net Core

Setup

1. Download at https://www.nuget.org/packages/MapOnly
2. Install by command lines: Install-Package MapOnly -Version 0.2.1 ( current version)
3. Install by nuget manage: Search MapOnly -> select project want to install -> click install

Method

1. Create

This method uses to create a mapping between 2 classes. If the classes had the same properties no need to do create a mapping. MapOnly automatic find and do the mapping.

Syntax

using MapOnly;
...
MapExtension.Create<ClassSource, ClassDestination>()
...

Example

MapExtension.Create<UserViewModel, User>()

2. Add

Normally, If the classes had the same properties name and the same data type, no need to use this method. This method uses to declare with MapOnly a property of ClassSource mapping to a property of ClassDestination. or A property of ClassDestination mapping to a value.

Syntax

using MapOnly;
...
MapExtension.Create<ClassSource, ClassDestination>().Add(a => a.Property1,b => b.Property2);
MapExtension.Create<ClassSource, ClassDestination>().Add(b => b.Property1,"Value");
...

Example

MapExtension.Create<UserViewModel, User>()
			.Add(v => v.DisplayName, u => u.FullName)
			.Add(u.CreatedBy, "Admin"); // Version 0.2.0

3. Ignore

In the case, class Destination and class Source have some properties are different or we don't want to do the mapping for the properties. We can use the Ignore method.

Syntax

using MapOnly;
...
MapExtension.Create<ClassSource, ClassDestination>().Ingore(b => b.Property1); 
...

Example

MapExtension.Create<UserViewModel, User>()
                .Add(x =>x.Birthday, a => a.UpdatedDate)
                .Ignore(u => u.CreatedDate)
                .Ignore(u => u.CreatedUser)
                .Ignore(u => u.IsActive)
                .Ignore(u => u.UpdatedDate)
                .Ignore(u => u.UpdatedUser);

4. Map

This method use to convert a object to another object follow setting or auto.

Syntax

 // a is an instant of Class Destination
 // b is an instant of Class Source
 b.Map(a);
 // or var a = b.Map(a);

Example

 var user = userViewModel.Map(new User());
 var viewModel = user.Map(new UserDetailsViewModel());
 var userListing = users
                  .Select(user => user.Map(new UserDetailsViewModel()))
                  .ToList();

Config

If between two classes had the properties need to ignore, or not mapping, or properties the same type but not the same name. We need to create mapping before we call the Map method.

Web

  // Create a MapOnlySetting class in App_Start/MapOnlySetting.cs 
  public static class MapOnlySetting
  {
	   public static void Register()
	   {
		    MapExtension.Create<A, A_Display>()
				        .Ignore(x => x.DisplayName)
					    .Add(source => source.Status, destination => destination.ProgressStatus);
	   }
  }

  // Call Register method in Application_Start
  protected void Application_Start() 
  {  
   MapOnlySetting.Register(); 
  }

Winform, Console...

// Can add config in the Main method in Program.cs file.
 static class Program
 {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
	        // Do the mapping config here
            MapOnlyConfig.Register();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new fmMain());
        } 
  }
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.
  • .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.

Version Downloads Last updated
0.2.1 579 6/27/2019
0.2.0 543 6/23/2019
0.0.1 767 4/7/2019