Example #1
0
        /// <summary>
        /// Fills the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public static void Fill(object source, object target)
        {
            IObjectProxy sourceProxy = Get(source);
            IObjectProxy targetProxy = Get(target);

            foreach (string propertyName in sourceProxy.PropertyNames)
            {
                targetProxy.SetValue(target, propertyName, sourceProxy.GetValue(source, propertyName));
            }
        }
Example #2
0
        /// <summary>
        /// Fills target object from source object, taking into account th fields to be avoided.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public void FillUpdate(object source, object target)
        {
            IObjectProxy proxy = ObjectProxyFactory.GetByType(this.EntityType);

            foreach (IMetamodelField field in this.Fields)
            {
                if (!field.AvoidUpdate)
                {
                    proxy.SetValue(target, field.Name, proxy.GetValue(source, field.Name));
                }
            }
        }
Example #3
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 #4
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);
        }