static public void CopyContent <TSource, TDest>(TSource source, TDest dest, params Expression <Func <object> >[] exceptFor)
            where TDest : TSource
        {
            if (object.ReferenceEquals(source, dest))
            {
                return;
            }

            var sourceProps = Introspector.GetAllPublicImplicitInstanceProps <TSource>();
            //var destProps = accessType == null ?
            //    Introspector.GetAllPubliInstanceProps<TDest>()
            //    : Introspector.GetAllPubliInstanceProps(accessType);

            var destProps = Introspector.GetAllPublicImplicitInstanceProps <TDest>();

            var exceptForNames = exceptFor.Select(x => FullNameOf.Property(x));

            var propsToCopy = sourceProps.Where(x => !exceptForNames.Contains(x.Name));

            foreach (var iProp in propsToCopy)
            {
                var sourceVal = iProp.GetValue(source);

                var destProp = destProps.Single(x => x.Name == iProp.Name);

                destProp.SetValue(dest, sourceVal);
            }
        }
Esempio n. 2
0
        static public IOrderedQueryable <T> OrderByDynamic <T>(this IQueryable <T> _this, Expression <Func <T, object> > startingPropPath, string propPath, SortOrderEnum order)
        {
            var typeOfItems = typeof(T);

            var exParam = Expression.Parameter(typeOfItems);


            var startingProps = FullNameOf.Property(startingPropPath).Split('.');
            var endingProps   = propPath.Split('.');

            var fullPropsPath = Enumerable.Concat(startingProps, endingProps);

            var exFullPropPath = _BuildPropertyAccessExpressionRec(exParam, fullPropsPath);

            var exSort = Expression.Lambda(exFullPropPath, exParam);


            var typeOfFinalProperty = exFullPropPath.Type;

            var exCallStaticMethodOnQueryableClass = Expression.Call
                                                     (
                type: typeof(Queryable),
                methodName: _GetSortMethodName(order),
                typeArguments: new[] { typeOfItems, typeOfFinalProperty },
                arguments: new[] { _this.Expression, exSort }

                                                     );

            var res = _this
                      .Provider
                      .CreateQuery <T>(exCallStaticMethodOnQueryableClass);

            return((IOrderedQueryable <T>)res);
        }
        static public bool AreEqual <TEntity>(TEntity obj1, TEntity obj2, params Expression <Func <object> >[] exceptFor)
        {
            var allProps = Introspector.GetAllPublicImplicitInstanceProps <TEntity>();

            var exceptForNames = exceptFor.Select(x => FullNameOf.Property(x));

            var propsToExamine = allProps.Where(x => !exceptForNames.Contains(x.Name));

            return(propsToExamine
                   .All(x => object.Equals(x.GetValue(obj1), x.GetValue(obj2))));
        }
        public static void CopyContent <TSource>(TSource source, OxUpdateProperty oxUpdateProperty, params Expression <Func <object> >[] exceptFor)
        {
            var sourceProps = Introspector.GetAllPublicImplicitInstanceProps <TSource>();

            var exceptForNames = exceptFor.Select(x => FullNameOf.Property(x));

            var propsToCopy = sourceProps.Where(x => !exceptForNames.Contains(x.Name));

            foreach (var iProp in propsToCopy)
            {
                var sourceVal = iProp.GetValue(source);

                oxUpdateProperty.Invoke(iProp.Name, sourceVal);
            }
        }
Esempio n. 5
0
        static public string Property <TOwner, TResult>(Expression <Func <TOwner, TResult> > exProp)
        {
            var fullName = FullNameOf.Property(exProp);

            return(fullName.Split(FullNameOf.DotSymbol.Single()).Last());
        }