Giter VIP home page Giter VIP logo

propmapper's Introduction

PropMapper

Property mapper for .NET. Flat and basic, but VERY FAST.

Just one cs-file, only 80 lines of code.

Installation

Drop the cs-file into your project OR install via Nuget

Install-Package PropMapper

(this will will simply add the .cs file to your project, not a DLL-reference, so you're free of dependencies)

Usage

Just one line of code:

//instantiating a new object
DestType destObject = PropMapper<SourceType, DestType>.From(srcObj);

or

//using with existing objects
PropMapper<SourceType, DestType>.CopyTo(srcObj, destObj);

Benchmarks

Mapping a simple object with 50 properties, over 100k iterations.

Results:

Mapper Results
Automapper 32490ms
Automapper with cached config object 335ms
PropMapper 25ms
Manual code 10ms

PropMapper is more than 13 times faster. Here's the class we tested on:

public class Tester
{
	public string prop1 { get; set; }
	public string prop2 { get; set; }
	public string prop3 { get; set; }
	public int iprop1 { get; set; }
	//etc. 50 times
}

Under the hood

We use compiled Expression trees, created in the static constructor and cached in a var, which makes it really fast.

Use case: casting base class to derived class

public class Person
{
	public string FirstName { get; set; }
	public string LastName { get; set; }
}
public class Employee : Person
{
	public string Title { get; set; }
	
	public Employee(Person person)
	{
		PropMapper<Person, Employee>.CopyTo(person, this);
	}
}

What's next?

Currently it's just one C# file, with unit tests, a proper library and more benchmarks coming later. The tool is in heavy use in other projects of ours, so it's regularly unit-tested anyway.

propmapper's People

Contributors

alex-jitbit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.