You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-3
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,11 @@ This is why this library consists of simple interfaces for object mapping contra
11
11
12
12
## Usage
13
13
14
-
Install NuGet package to your project - you can find current release [here](https://www.nuget.org/packages/SimpleObjectMapper/). This will add ObjectMapper.Framework to your references and diagnostic analyser under analyzers node.
15
-
You can then use mapper interfaces from ObjectMapper.Framework assembly to define mapping. For example let's define two classes with some matching properties:
14
+
Install NuGet package to your project - you can find current release [here](https://www.nuget.org/packages/SimpleObjectMapper/). This will add ObjectMapper.Framework to your references and diagnostic analyser under analyzers node. You can then use mapper interfaces or attribute from ObjectMapper.Framework assembly to define mapping.
15
+
16
+
### IObjectMapper<T> interface
17
+
18
+
Let's define two classes with some matching properties:
16
19
17
20
```C#
18
21
usingObjectMapper.Framework;
@@ -42,7 +45,7 @@ namespace TestClassLibrary
42
45
}
43
46
```
44
47
45
-
Let's say that we want to define mapping from class ClassA to ClassB. We specify that ClassA implements IObjectMapper<ClassB> interface. If we have cursor on IObjectMapper<ClassB> symbol, Visual Studio will display lightbulb on the right side. By clicking on lightbulb (or using space + . shortcut), you will get menu of options. If you click 'Generate implementation' interface implementation with mapping code will be generated for you. For the above example result is as follows:
48
+
Let's say that we want to define mapping from class ClassA to ClassB. We specify that ClassA implements IObjectMapper<ClassB> interface. If we have caret on IObjectMapper<ClassB> symbol, Visual Studio will display lightbulb on the right side. By clicking on lightbulb (or using left control + . shortcut), you will get menu of options. If you click 'Generate implementation' interface implementation with mapping code will be generated for you. For the above example result is as follows:
46
49
47
50
```C#
48
51
usingObjectMapper.Framework;
@@ -80,8 +83,56 @@ namespace TestClassLibrary
80
83
}
81
84
```
82
85
86
+
If you have method already defined (or generated), you can set caret on method name and 'Generate implementation' action will be available.
87
+
88
+
### IObjectMapperAdapter<T, U> interface
89
+
83
90
If you do not want to have mapping code inside your POCO classes you can use IObjectMapperAdapter<T,U>. By having cursor on IObjectMapperAdapter symbol, you can invoke 'Generate implementation' and generator will generate mapping code for mapping from class T to class U and from class U to class T.
84
91
92
+
If we take previous example of ClassA and ClassB and we define new class Adapter which implements IObjectMapperAdapter<ClassA, ClassB> generated code for Adapter class is as follows:
If you want to have ad hoc method for mapping without actually implementing one of the above interfaces, you can annotate mapping method with ObjectMapperMethodAttribute attribute. This attribute can be applied only to methods with following signatures:
118
+
- Method accepts exactly two parameters
119
+
- Method return type is void
120
+
121
+
Compile time error will be raised otherwise. If you then place caret on method name, lightbulb will apear and 'Generate implementation' action will be available.
0 commit comments