public ClassMappingInstructionContext AddMapping(ClassMappingInstruction mapping) { // TODO: Validate duplicated mappings _mappingInstructions.Add(mapping); return(new ClassMappingInstructionContext(this, mapping)); }
public object Map(object source, Type sourceType, Type destinationType) { // TODO: hashed search (dictionary?) ClassMappingInstruction mapping = _mappingInstructions.MappingInstructions .FirstOrDefault(_ => _.SourceType == sourceType && _.DestinationType == destinationType) ?? throw new Exceptions.NoMappingFoundException($"Couldn't find mapping from {sourceType.FullName} to {destinationType.FullName}"); object destination = Activator.CreateInstance(destinationType); mapping.Map(source, destination); return(destination); }
public ClassMappingInstructionContext(ClassMappingInstructionHolder holder, ClassMappingInstruction mapping) { Holder = holder; Mapping = mapping; }
public ClassMappingInstructionContext AddMapping <T1, T2>(ClassMappingInstructionOptions options) { ClassMappingInstruction mapping = ClassMappingInstruction.FromTypes <T1, T2>(options); return(AddMapping(mapping)); }