//protected override Expression VisitParameter(ParameterExpression p) //{ // if (p.Type.IsGenericType && p.Type.GetGenericTypeDefinition() == typeof(IGrouping<,>)) // _isBlocked = true; // return base.VisitParameter(p); //} private static bool IsCollection(Type type) { //HACK: this is going to generally subvert custom objects that implement ICollection or ICollection<T>, //but are not collections if (type.IsGenericType) { type = type.GetGenericTypeDefinition(); } return(CollectionTypes.Any(x => x.IsAssignableFrom(type))); }
private CloneDelegate <TEntity> AssembleExpression <TEntity>(IExpressionBuilder expressionBuilder) where TEntity : class { CloneExpressionContext context = new CloneExpressionContext { SourceEntity = expressionBuilder.AddParameter <TEntity>(nameof(CloneExpressionContext.SourceEntity)), CloneFactory = expressionBuilder.AddParameter <ICloneFactory>(nameof(CloneExpressionContext.CloneFactory)), }; if (CollectionTypes.Any(collectionType => IsCollectionType(collectionType, typeof(TEntity)))) { AddCollectionExpressions <TEntity>(expressionBuilder, context); } else { AddCloneExpressions <TEntity>(expressionBuilder, context); } expressionBuilder.ReturnObject(context.TargetEntity); return(expressionBuilder.Build <CloneDelegate <TEntity> >()); }