public static T SurroundConstruct <T>(this ConstructorContext ctx, Func <ConstructorContext, T> constructor)
            where T : ModifiableEntity
        {
            ctx.Type = typeof(T);

            return((T)Manager.SurroundConstruct(ctx, constructor));
        }
        public virtual ModifiableEntity ConstructCore(ConstructorContext ctx)
        {
            Func <ConstructorContext, ModifiableEntity> c = Constructors.TryGetC(ctx.Type);

            if (c != null)
            {
                ModifiableEntity result = c(ctx);
                if (result != null)
                {
                    return(result);
                }
            }

            if (ctx.Type.IsEntity() && OperationLogic.HasConstructOperations(ctx.Type))
            {
                return(OperationClient.Manager.Construct(ctx));
            }

            return((ModifiableEntity)Activator.CreateInstance(ctx.Type, true));
        }
        public virtual ModifiableEntity SurroundConstruct(ConstructorContext ctx, Func <ConstructorContext, ModifiableEntity> constructor)
        {
            using (Disposable.Combine(PreConstructors, f => f(ctx)))
            {
                var entity = constructor(ctx);

                if (entity == null)
                {
                    return(null);
                }

                if (PostConstructors != null)
                {
                    foreach (var post in PostConstructors.GetInvocationListTyped())
                    {
                        post(ctx, entity);
                    }
                }

                return(entity);
            }
        }
        public static void PostConstructors_AddFilterProperties(ConstructorContext ctx, ModifiableEntity entity)
        {
            HttpContextBase httpContext = ctx.Controller.ControllerContext.HttpContext;

            if (!httpContext.Request.Params.AllKeys.Contains("webQueryName"))
            {
                return;
            }

            if (!(entity is Entity))
            {
                return;
            }

            object queryName = Finder.ResolveQueryName(httpContext.Request.Params["webQueryName"]);

            if (entity.GetType() != queryName as Type)
            {
                return;
            }

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(queryName);

            var filters = FindOptionsModelBinder.ExtractFilterOptions(httpContext, queryDescription)
                          .Where(fo => fo.Operation == FilterOperation.EqualTo);

            var pairs = from pi in ctx.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                        join fo in filters on pi.Name equals fo.Token.Key
                        //where CanConvert(fo.Value, pi.PropertyType) && fo.Value != null
                        where fo.Value != null
                        select new { pi, fo };

            foreach (var p in pairs)
            {
                p.pi.SetValue(entity, Common.Convert(p.fo.Value, p.pi.PropertyType), null);
            }

            return;
        }
        public static ModifiableEntity SurroundConstructUntyped(this ConstructorContext ctx, Type type, Func <ConstructorContext, ModifiableEntity> constructor)
        {
            ctx.Type = type;

            return(Manager.SurroundConstruct(ctx, constructor));
        }
 public static ModifiableEntity ConstructUntyped(this ConstructorContext ctx, Type type)
 {
     return(ctx.SurroundConstructUntyped(type, Manager.ConstructCore));
 }
 public static T Construct <T>(this ConstructorContext ctx)
     where T : ModifiableEntity
 {
     return((T)ctx.SurroundConstructUntyped(typeof(T), Manager.ConstructCore));
 }