Ejemplo n.º 1
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();
                }
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }