public CustomConverterDescriptor GetCustomConverterDescr( Type from, Type to, MapConfigBaseImpl mappingConfig) { var tFromTypeArgs = DefaultCustomConverterProvider.GetGenericArguments(from); var tToTypeArgs = DefaultCustomConverterProvider.GetGenericArguments(to); if (tFromTypeArgs == null || tToTypeArgs == null || tFromTypeArgs.Length != 1 || tToTypeArgs.Length != 1) { return(null); } var tFrom = tFromTypeArgs[0]; var tTo = tToTypeArgs[0]; if (tFrom == tTo && (tFrom.IsValueType || mappingConfig.GetRootMappingOperation(tFrom, tTo).ShallowCopy)) { return(new CustomConverterDescriptor { ConversionMethodName = "Convert", ConverterImplementation = typeof(ArraysConverter_OneTypes <>), ConverterClassTypeArguments = new[] { tFrom } }); } return(new CustomConverterDescriptor { ConversionMethodName = "Convert", ConverterImplementation = typeof(ArraysConverter_DifferentTypes <,>), ConverterClassTypeArguments = new[] { tFrom, tTo } }); }
public void Initialize(Type from, Type to, MapConfigBaseImpl mappingConfig) { var staticConverters = mappingConfig.GetStaticConvertersManager() ?? StaticConvertersManager.DefaultInstance; var staticConverterMethod = staticConverters.GetStaticConverter(typeof(TFrom), typeof(TTo)); if (staticConverterMethod != null) { //CoreMigrated // _converter = (Func<TFrom, TTo>)Delegate.CreateDelegate( // typeof(Func<TFrom, TTo>), // null, // staticConverterMethod //); _converter = (Func <TFrom, TTo>)staticConverterMethod.CreateDelegate( typeof(Func <TFrom, TTo>), null ); } else { _subMapper = ObjectMapperManager.DefaultInstance.GetMapperInt(typeof(TFrom), typeof(TTo), mappingConfig); _converter = ConverterBySubmapper; } }
/// <summary> /// Gets the custom converter descr. /// </summary> /// <param name="from">The from.</param> /// <param name="to">The to.</param> /// <param name="mappingConfig">The mapping config.</param> /// <returns>A CustomConverterDescriptor.</returns> public CustomConverterDescriptor GetCustomConverterDescr(Type from, Type to, MapConfigBaseImpl mappingConfig) { var tFromTypeArgs = DefaultCustomConverterProvider.GetGenericArguments(from); var tToTypeArgs = DefaultCustomConverterProvider.GetGenericArguments(to); if (tFromTypeArgs == default || tToTypeArgs == default || tFromTypeArgs.Length != 1 || tToTypeArgs.Length != 1) { return(default);
public virtual CustomConverterDescriptor GetCustomConverterDescr( Type from, Type to, MapConfigBaseImpl mappingConfig) { return new CustomConverterDescriptor { ConverterClassTypeArguments = GetGenericArguments(from).Concat(GetGenericArguments(to)).ToArray(), ConverterImplementation = _converterType, ConversionMethodName = "Convert" }; }
/// <summary> /// Gets the custom converter descr. /// </summary> /// <param name="from">The from.</param> /// <param name="to">The to.</param> /// <param name="mappingConfig">The mapping config.</param> /// <returns>A CustomConverterDescriptor.</returns> public virtual CustomConverterDescriptor GetCustomConverterDescr(Type from, Type to, MapConfigBaseImpl mappingConfig) { return(new CustomConverterDescriptor { ConverterClassTypeArguments = GetGenericArguments(from).Concat(GetGenericArguments(to)), ConverterImplementation = _converterType, ConversionMethodName = "Convert" }); }