private Assignment ProcessTypeMap(TypeMap rootMap, string srcFieldName, string destFieldName) { var coder = new Coder(); foreach (PropertyMap propertyMap in rootMap.PropertyMaps) { RememberTypeLocations(propertyMap); var context = new PropertyNameContext(propertyMap, srcFieldName, destFieldName); if (propertyMap.Ignored) { continue; } //assign without explicit cast if (propertyMap.DestType.IsAssignableFrom(propertyMap.SrcType) || propertyMap.DestType.IsImplicitCastableFrom(propertyMap.SrcType)) { //TODO: need to determine explicit casts and produce cast operators coder.SimpleAssign(context); continue; } else { bool referenceType = propertyMap.DestType.IsClass; //TODO: perfomance degrades on each null check! Try to avoid it if possible! if (referenceType) { coder.NullCheck(context); coder.AttachRawCode(" else {{"); coder.AppendNoParameterlessCtorException(context, propertyMap.DestType); } ProcessPropertyTypePair(coder, context, propertyMap); if (referenceType) { coder.AttachRawCode("}}"); } } } var assignment = coder.GetAssignment(); TemplateCache.AddIfNotExist(rootMap.TypePair, assignment.RelativeTemplate); return(assignment); }