Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
 public BotConfiguration(Type constructingType, ConstructorDefinition constructor)
 {
     ConstructingType = constructingType;
     Constructor      = constructor;
 }