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); return(result); } if (ctx.Type.IsEntity() && OperationClient.Manager.HasConstructOperations(ctx.Type)) { return(OperationClient.Manager.Construct(ctx)); } return((ModifiableEntity)Activator.CreateInstance(ctx.Type)); }
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(); } } }
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); } } }
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); }
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)); }