Example #1
0
        /// <summary>
        /// Creates an instance of target type and fills from a string map.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        public static T FromStringMap <T>(Dictionary <string, string> map)
        {
            IObjectProxy proxy  = Get <T>();
            T            result = (T)proxy.CreateObject();

            proxy.ReadFromStringMap(result, map);
            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>
        /// 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 #4
0
        /// <summary>
        /// Converts a list of string maps to a list of instances.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        public static IList <T> FromListStringMap <T>(IList <Dictionary <string, string> > map)
        {
            if (map == null)
            {
                return(null);
            }
            IObjectProxy proxy  = Get <T>();
            IList <T>    result = (IList <T>)proxy.CreateList();

            foreach (Dictionary <string, string> row in map)
            {
                T item = (T)proxy.CreateObject();
                proxy.ReadFromStringMap(item, row);
                result.Add(item);
            }
            return(result);
        }