private object Create(ConstructorDefinition constructor) { var obj = constructor.Create(); try { BeforeBindingHook(obj); } catch (Exception ex) { throw new BuildFailedException($"Failed process BeforeBindingHook on creation of {ConstructingType}. See InnerException for more details.", ex); } foreach (var property in Properties) { property.Apply(obj); } try { AfterBindingHook(obj); } catch (Exception ex) { throw new BuildFailedException($"Failed process AfterBindingHook on creation of {ConstructingType}. See InnerException for more details.", ex); } return(obj); }
public object CreateNewObjectWithModification(ConstructorDefinition modification) { if (Constructor.Constructor != modification.Constructor) { var constructor = new ConstructorDefinition(modification.Constructor, modification.Arguments); return(Create(constructor)); } var args = new IGenerator[Constructor.Arguments.Count]; for (var i = 0; i < args.Length; i++) { var modifiedArg = modification.Arguments[i]; args[i] = modifiedArg is KeepGenerator ? Constructor.Arguments[i] : modifiedArg; } var patchedConstructor = new ConstructorDefinition(Constructor.Constructor, args); return(Create(patchedConstructor)); }
public BotConfiguration(Type constructingType, ConstructorDefinition constructor) { ConstructingType = constructingType; Constructor = constructor; }