private static Expression CreateCloneExpression(
            ParameterExpression source, ParameterExpression destination, ParameterExpression cache)
        {
            var targets = CopyMemberExtractor.Extract <T>();

            var expressions = new ReadOnlyCollectionBuilder <Expression>(
                CreateExpressions(targets, source, destination, cache));

            //var expressions = CreateExpressions(targets, source, destination);

            return(Expression.Block(expressions));
        }
示例#2
0
        private static Expression CreateCloneExpression(Type type,
                                                        Expression source, Expression destination, Expression cache)
        {
            var targets = CopyMemberExtractor.Extract(type);

            //System.Diagnostics.Debug.WriteLine($"{typeof(T)}");
            //foreach (var target in targets)
            //{
            //    var type = target.Item1 is FieldInfo field ? field.FieldType
            //        : ((PropertyInfo)target.Item1).PropertyType;
            //    System.Diagnostics.Debug.WriteLine($" - {type} : {target.Item1.Name}");
            //}

            var expressions = new ReadOnlyCollectionBuilder <Expression>(
                CreateExpressions(targets, source, destination, cache));

            //var expressions = CreateExpressions(targets, source, destination);
            return(expressions.Any()
                ? Expression.Block(expressions)
                : Expression.Empty());
        }