/// <inheritdoc /> public object Transform(object originalParameter, TypeInfo destinationParameterType) { ParameterTransformerCacheEntry transformer = this.transformerCache.GetTransformer(destinationParameterType); if (transformer == null) { return(null); } object destinationParameter = transformer.ParameterFactory(destinationParameterType); return(transformer.Transformer(originalParameter, destinationParameter)); }
/// <summary> /// Gets a transformer by its type info key. /// </summary> /// <param name="type">TypeInfo key.</param> /// <returns> /// Existing <see cref="ParameterTransformerCacheEntry"/>; otherwise the system creates it and caches it. /// </returns> public ParameterTransformerCacheEntry GetTransformer(TypeInfo type) { if (!this.cache.TryGetValue(type, out ParameterTransformerCacheEntry transformer)) { TransformerModel transformerModel = this.GetTransformerModel(type); if (transformerModel == null) { return(null); } transformer = new ParameterTransformerCacheEntry( transformerModel.Source, transformerModel.Destination, type, this.parameterFactory.Create, transformerModel.Transformer); this.cache.Add(type, transformer); } return(transformer); }