public LogMessageTranslator() { logMessageTranslator = new MappersCollection(); logMessageTranslator.Add <InitializationOfUnitTestHarnessClientEventMap>(); logMessageTranslator.Add <TestExecutionClassBeginClientEventMap>(); logMessageTranslator.Add <TestExecutionClassCompletedClientEventMap>(); logMessageTranslator.Add <TestExecutionMethodBeginClientEventMap>(); logMessageTranslator.Add <TestExecutionMethodIgnoredClientEventMap>(); logMessageTranslator.Add <TestExecutionMethodFailedClientEventMap>(); logMessageTranslator.Add <TestExecutionMethodPassedClientEventMap>(); logMessageTranslator.Add <TestExecutionDoNotReportMessageMap>(); }
public void To <TO>(ref TO targetObj) where TO : new() { var srcType = typeof(TI); var targetType = typeof(TO); var key = ComputeMapperKey(srcType, targetType, 0x01); if (AssignersCollection.TryGetValue(key, out var del) == false) { var param = Expression.Parameter(srcType, "src"); var target = Expression.Parameter(targetType.MakeByRefType(), "target"); var srcMembers = param.Type.GetFieldsAndProperties(); var targetMembers = target.Type.GetFieldsAndProperties(); var memberAssignments = targetMembers.Join(srcMembers, mem => mem.Name, mem => mem.Name, (targetMember, sourceMember) => Expression.Assign(Expression.PropertyOrField(target, targetMember.Name), Expression.PropertyOrField(param, sourceMember.Name))); var body = Expression.Block(memberAssignments); del = Expression.Lambda <Assign <TI, TO> >(body, param, target).Compile(); MappersCollection.Add(key, del); } ((Assign <TI, TO>)del)(_src, ref targetObj); }
public TO To <TO>() where TO : new() { var srcType = typeof(TI); var targetType = typeof(TO); var key = ComputeMapperKey(srcType, targetType, 0x10); if (MappersCollection.TryGetValue(key, out var del) == false) { var param = Expression.Parameter(srcType, "src"); var srcMembers = param.Type.GetFieldsAndProperties(); var targetMembers = targetType.GetFieldsAndProperties(); var memberAssignments = targetMembers.Join(srcMembers, mem => mem.Name, mem => mem.Name, (targetMember, sourceMember) => Expression.Bind(targetMember, Expression.PropertyOrField(param, sourceMember.Name))); var init = Expression.MemberInit(Expression.New(targetType), memberAssignments); del = Expression.Lambda <Func <TI, TO> >(init, param).Compile(); MappersCollection.Add(key, del); } var temp = new TO(); return(((Func <TI, TO>)del)(_src)); }