コード例 #1
0
        public ClassMappingInstructionContext AddMapping(ClassMappingInstruction mapping)
        {
            // TODO: Validate duplicated mappings

            _mappingInstructions.Add(mapping);
            return(new ClassMappingInstructionContext(this, mapping));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public ClassMappingInstructionContext(ClassMappingInstructionHolder holder, ClassMappingInstruction mapping)
 {
     Holder  = holder;
     Mapping = mapping;
 }
コード例 #4
0
        public ClassMappingInstructionContext AddMapping <T1, T2>(ClassMappingInstructionOptions options)
        {
            ClassMappingInstruction mapping = ClassMappingInstruction.FromTypes <T1, T2>(options);

            return(AddMapping(mapping));
        }