예제 #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;
 }