Exemplo n.º 1
0
        /// <summary>
        ///     원본 프로바이더인 <paramref name="sourceProvider"/> 를 대상 프로바이더인 <paramref name="targetProvider"/> 로 매핑을 수행합니다.
        /// </summary>
        /// <param name="sourceProvider">	<see cref="IMappingProvider"/> 를 구현하는 원본 프로바이더 객체입니다. </param>
        /// <param name="targetProvider">	<see cref="IMappingProvider"/> 를 구현하는 원본 프로바이더 객체입니다.	</param>
        protected void Assign(IMappingProvider sourceProvider, IMappingProvider targetProvider)
        {
            var sourceKeys = sourceProvider.MappingKeys;

            //while( sourceProvider.MoveNext() && targetProvider.CanCreateNewInstance)
            //{
            //    sourceProvider.MoveNext();

            var sbDebug = new StringBuilder(2048);

            sbDebug.AppendLine("Assign");
            sbDebug.AppendLine(string.Format("sourceProvider:{0}, targetProvider:{1}", sourceProvider.GetObject().GetType(), targetProvider.GetObject().GetType()));

            targetProvider.StartOfAssign(sourceProvider, targetProvider);
            foreach (var key in sourceKeys)
            {
                if (sourceProvider.CanGetter(key) != true)
                {
                    continue;
                }

                var sourceValue = sourceProvider.Getter(key);
                if (sourceValue is DBNull || sourceValue == DBNull.Value)
                {
                    continue;
                }

                if (targetProvider.CanSetter(key) != true)
                {
                    continue;
                }
                if (this.Mapper.ContainsKey((TInput)key))
                {
                    this.GetMappingValue((TInput)key);
                }
                else
                {
                    if (sourceProvider is IMappingCollectionProvider && targetProvider is IMappingCollectionProvider)
                    {
                        this.Map((TInput)key).Return(o => ((IMappingCollectionProvider)targetProvider).SetValues(targetProvider.CreateNewInstance(), ((IMappingCollectionProvider)sourceProvider).GetValues(sourceValue)));
                        this.GetMappingValue((TInput)key);
                        continue;
                    }

                    this.Map((TInput)key).Return(o => targetProvider.Setter(o, sourceValue));
                    this.GetMappingValue((TInput)key);

                    if (sourceValue != null && sourceValue.GetType() == typeof(byte[]))
                    {
                        sourceValue = "byte[] { " + BitConverter.ToString((byte[])sourceValue) + " }";
                    }

                    sbDebug.AppendLine(string.Format("\t{0}.{1} => {2}.{3} = {4}", sourceProvider.GetObject().GetType().Name, key,
                                                     targetProvider.GetObject().GetType().Name, key,
                                                     sourceValue));
                }
            }

            targetProvider.EndOfAssign(sourceProvider, targetProvider);

            logger.Info(sbDebug);
            //}
        }