public static IncludeDirective GetIncludeInCollectionDirective(MemberExpression collectionMemberExp, LambdaExpression collectionFieldSelector) { var parameter = ExpressionUtil.GetParameterExpression(collectionMemberExp); var collectionItemType = TypesUtil.GetGenericArgumentForBaseType(collectionMemberExp.Type, typeof(ICollection <>)); var delegateType = typeof(Func <,>).MakeGenericType(parameter.Type, typeof(IEnumerable <>).MakeGenericType(collectionItemType)); var collectionSelector = Expression.Lambda(delegateType, collectionMemberExp, parameter); var includeType = typeof(IncludeInCollectionDirective <,>).MakeGenericType(parameter.Type, collectionItemType); return(Activator.CreateInstance(includeType, collectionSelector, collectionFieldSelector) as IncludeDirective); }
public bool IsEntityCollection(Type t) { //?Todo: Also check if the generic type of the collection is IEntity if (t.IsGenericType && (typeof(ICollection <>).IsAssignableFrom(t.GetGenericTypeDefinition()))) { if (IsEntity(TypesUtil.GetGenericArgumentForBaseType(t, typeof(ICollection <>)))) { return(true); } else { return(false); } } else { return(false); } }