예제 #1
0
        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));
        }
예제 #2
0
        public virtual ModifiableEntity ConstructCore(ConstructorContext ctx)
        {
            Func <ConstructorContext, ModifiableEntity> c = Constructors.TryGetC(ctx.Type);

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

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

            return((ModifiableEntity)Activator.CreateInstance(ctx.Type));
        }
예제 #3
0
        public virtual ModifiableEntity SurroundConstruct(ConstructorContext ctx, Func <ConstructorContext, ModifiableEntity> constructor)
        {
            IDisposable disposable = null;

            try
            {
                foreach (var pre in PreConstructors.GetInvocationListTyped())
                {
                    disposable = Disposable.Combine(disposable, pre(ctx));

                    if (ctx.CancelConstruction)
                    {
                        return(null);
                    }
                }

                var entity = constructor(ctx);

                if (entity == null || ctx.CancelConstruction)
                {
                    return(null);
                }

                foreach (Action <ConstructorContext, ModifiableEntity> post in PostConstructors.GetInvocationListTyped())
                {
                    post(ctx, entity);

                    if (ctx.CancelConstruction)
                    {
                        return(null);
                    }
                }

                return(entity);
            }
            finally
            {
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
예제 #4
0
        public static void PostConstructors_AddFilterProperties(ConstructorContext ctx, ModifiableEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("result");
            }

            if (ctx.Element is SearchControl)
            {
                var filters = ((SearchControl)ctx.Element).FilterOptions.Where(fo => fo.Operation == FilterOperation.EqualTo && fo.Token is ColumnToken);

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

                foreach (var p in pairs)
                {
                    p.pi.SetValue(entity, Server.Convert(p.fo.Value, p.pi.PropertyType), null);
                }
            }
        }
예제 #5
0
        protected object OnCreate()
        {
            if (!CanCreate())
            {
                return(null);
            }

            object value;

            if (Creating == null)
            {
                Type type = SelectType(t => Navigator.IsCreable(t, isSearch: false));
                if (type == null)
                {
                    return(null);
                }

                object entity = new ConstructorContext(this).ConstructUntyped(type);

                value = entity;
            }
            else
            {
                value = Creating();
            }

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

            if (ViewOnCreate)
            {
                value = OnViewingOrNavigating(value, creating: true);
            }

            return(value);
        }
예제 #6
0
        public static ModifiableEntity SurroundConstructUntyped(this ConstructorContext ctx, Type type, Func <ConstructorContext, ModifiableEntity> constructor)
        {
            ctx.Type = type;

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