Example #1
0
        /// <summary>
        /// Maps to target.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public object MapToTarget(object source)
        {
            if (source == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxyTarget.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.srcToTgt)
            {
                proxyTarget.SetValue(result, entry.Value, proxySource.GetValue(source, entry.Key));
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Maps to source.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public object MapToSource(object target)
        {
            if (target == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxySource.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.tgtToSrc)
            {
                proxySource.SetValue(result, entry.Value, proxyTarget.GetValue(target, entry.Key));
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Adds default mapping.
        /// </summary>
        /// <returns></returns>
        public IMapper DefaultMap()
        {
            IObjectProxy   proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy   proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            IList <string> sourceNames = proxySource.PropertyNames.ToList();
            IList <string> targetNames = proxyTarget.PropertyNames.ToList();

            foreach (string sourceName in sourceNames)
            {
                if (targetNames.IndexOf(sourceName) > -1)
                {
                    this.AddPropertyMap(sourceName, sourceName);
                }
            }
            return(this);
        }