C#-working-notes
Basic grammer#
How to call async method in sync method#
suppose function A() is marked as async, if we want to call A in function B, usually we use await and marked b as async. However, if we dont want to modify the return type of B. To solve that, I decide to use anonymous function to encapsulate the calling of function A, then receive the return_val of A sync.
1 | public int B(){ |
Utility#
ELMAH#
log4net#
#
Introduction#
AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper’s established convention, almost zero configuration is needed to map two types.
Usage#
Once you have your types you can create a map for the two types using a MapperConfiguration and CreateMap. You only need one MapperConfiguration instance typically per AppDomain and should be instantiated during startup. More examples of initial setup see in Setup.
1 | var config = new MapperConfiguration(cfg => cfg.CreateMap<Order, OrderDto>()); |
The type on the left is the source type, and the type on the right is the destination type. To perform a mapping, call one of the Map overloads:
1 | var mapper = config.CreateMapper(); |
1 | var obj2 = Mapper.Map<Obj1, Obj2>(obj1); |