コード例 #1
0
        internal static void UpdateSalesPerson(this ReverseMapper mapper, SalesPerson source, Sample.Business.SalesPerson target)
        {
            // Verify null args:
            if (Object.ReferenceEquals(source, null))
            {
                return;
            }
            else if (Object.ReferenceEquals(target, null))
            {
                throw new Max.Domain.Mapping.MappingException("No target provided to map SalesPerson on.");
            }

            // Map source to target:
            mapper.UpdateEmployee(source, target);
            if (target.SalesQuota != source.SalesQuota)
            {
                target.SalesQuota = source.SalesQuota;
            }
            if (target.Bonus != source.Bonus)
            {
                target.Bonus = source.Bonus;
            }
            if (target.CommissionPct != source.CommissionPct)
            {
                target.CommissionPct = source.CommissionPct;
            }
            if (target.SalesYTD != source.SalesYTD)
            {
                target.SalesYTD = source.SalesYTD;
            }

            // Call partial AfterUpdate method:
            AfterUpdateSalesPerson(mapper, source, target);
        }
コード例 #2
0
        public static Sample.Business.Employee MapFromEmployee(this ReverseMapper mapper, Employee source, Sample.Business.Employee target)
        {
            // Null maps to null:
            if (source == null)
            {
                return(null);
            }

            // Check if object already mapped (as in circular reference scenarios):
            object mappedTarget = mapper.GetMappedTarget(source);

            if (Object.ReferenceEquals(mappedTarget, null) == false)
            {
                return((Sample.Business.Employee)mappedTarget);
            }

            // Retrieve target object:
            if (target == null)
            {
                target = mapper.TryGetTarget <Sample.Business.Employee>(source);
            }
            if (target == null)
            {
                throw new Max.Domain.Mapping.MappingException(String.Format("Cannot map {0} to an existing instance.", source.GetType().Name));
            }

            // Register mapping:
            mapper.RegisterMapping(source, target);

            // Perform mapping:
            if (mapper.CanUpdate(target))
            {
                mapper.UpdateEmployee(source, target);
            }

            // Return target:
            return(target);
        }