コード例 #1
0
        protected void DefaultPropertyMapping(
            object destination, Type destType, TypeInfo destTypeInfo,
            object source, Type srcType, TypeInfo srcTypeInfo,
            Configuration config)
        {
            var destProperties = ModelingHelper.GetMembers(destType);
            var srcProperties  = ModelingHelper.GetMembers(srcType, property => property.CanRead)
                                 .Select(x => new ExtendedProperyInfo(x, srcType))
                                 .ToArray();

            var matchFinder = config.MatchFinder;
            var skipNulls   = config.SkipNulls;

            var evaluations = new List <ExtendedProperyInfo>();

            foreach (var prop in destProperties)
            {
                var destinationExtendedInfo = new ExtendedProperyInfo(prop, destType);

                if (destinationExtendedInfo.GetEvaluationRequired(srcType, source))
                {
                    evaluations.Add(destinationExtendedInfo);
                    continue;
                }
                //var rName = prop.Name;

                var srcProp = srcProperties.FirstOrDefault(x => matchFinder(config, destinationExtendedInfo, x));

                if (srcProp != null)
                {
                    var result = srcProp.MemberInfo.GetValue(source);
                    if (!skipNulls || result != null || destinationExtendedInfo.PassNullsToCast)
                    {
                        var castExpression = destinationExtendedInfo.CastExpression;
                        if (castExpression != null)
                        {
                            result = castExpression(result);
                        }
                        prop.SetValue(destination, result);
                    }
                }
            }

            foreach (var prop in evaluations)
            {
                var result = prop.EvaluateExpression(source);

                if (!skipNulls || result != null)
                {
                    prop.MemberInfo.SetValue(destination, result);
                }
            }
        }
コード例 #2
0
ファイル: ModelingDesigner.cs プロジェクト: yungtau/oea
 /// <summary>
 /// 获取某个元素外部的设计器。
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 public static ModelingDesigner GetDesigner(DependencyObject element)
 {
     return(ModelingHelper.GetVisualParent <ModelingDesigner>(element));
 }
コード例 #3
0
        protected void DefaultPropertyMapping(MapperCacheContext cacheContext,
                                              object destination, Type destType, TypeInfo destTypeInfo,
                                              object source, Type srcType, TypeInfo srcTypeInfo,
                                              MapperContext context, int cLevel, int topLevel)
        {
            MappingProperyInfo[] destPropertyInfos;
            MappingProperyInfo[] srcPropertyInfos;
            var destProperties = cacheContext.GetState(destType, out destPropertyInfos)
                ? destPropertyInfos
                : ModelingHelper.GetMembers(destType).Select(x => new MappingProperyInfo(x, destType));
            var srcProperties = cacheContext.GetState(srcType, out srcPropertyInfos)
                ? srcPropertyInfos
                : ModelingHelper.GetMembers(srcType, property => property.CanRead)
                                .Select(x => new MappingProperyInfo(x, srcType))
                                .ToArray();

            var matchFinder = context.MatchFinder;
            var skipNulls   = context.SkipNulls;

            var evaluations = new List <MappingProperyInfo>();

            foreach (var destProp in destProperties)
            {
                if (destProp.IsEvaluationRequired(srcType, source))
                {
                    evaluations.Add(destProp);
                    continue;
                }
                //var rName = prop.Name;

                var srcProp = srcProperties.FirstOrDefault(x => matchFinder(context, destProp, x));

                if (srcProp != null)
                {
                    var result = srcProp.MemberInfo.GetValue(source);
                    if (!skipNulls || result != null || destProp.PassNullsToCast)
                    {
                        if (_isDeepMappingStrategy(destProp.PropertyType, destProp.PropertyTypeInfo) &&
                            cLevel < topLevel)
                        {
                            object destPropBuffer = null;
                            _map(cacheContext,
                                 ref destPropBuffer, destProp.PropertyType, destProp.PropertyTypeInfo,
                                 result, srcProp.PropertyType, srcProp.PropertyTypeInfo,
                                 context, cLevel + 1, topLevel);
                        }
                        else
                        {
                            var castExpression = destProp.CastExpression;
                            if (castExpression != null)
                            {
                                result = castExpression(result);
                            }
                            destProp.MemberInfo.SetValue(destination, result);
                        }
                    }
                }
            }

            foreach (var prop in evaluations)
            {
                var result = prop.EvaluateExpression(source);

                if (!skipNulls || result != null)
                {
                    prop.MemberInfo.SetValue(destination, result);
                }
            }
        }