private void SetComponentProperties(IPipelineComponent component, string propertyName, object value) { var d = (PipelineComponentArgument)component.GetAllArguments().Single(a => a.Name.Equals(propertyName)); d.SetValue(value); d.SaveToDatabase(); }
private object CreateComponent(IPipelineComponent toBuild) { var type = toBuild.GetClassAsSystemType(); if (type == null) { throw new Exception("Could not find Type '" + toBuild.Class + "'"); } object toReturn = _constructor.Construct(type); //all the IArguments we need to initialize the class var allArguments = toBuild.GetAllArguments().ToArray(); //get all possible properties that we could set on the underlying class foreach (var propertyInfo in toReturn.GetType().GetProperties()) { SetPropertyIfDemanded(toBuild, toReturn, propertyInfo, allArguments); //see if any demand nested initialization Attribute nestedInit = System.Attribute.GetCustomAttributes(propertyInfo) .FirstOrDefault(a => a is DemandsNestedInitializationAttribute); //this one does if (nestedInit != null) { // initialise the container before nesting-setting all properties var container = Activator.CreateInstance(propertyInfo.PropertyType); foreach (var nestedProp in propertyInfo.PropertyType.GetProperties()) { SetPropertyIfDemanded(toBuild, container, nestedProp, allArguments, propertyInfo); } //use reflection to set the container propertyInfo.SetValue(toReturn, container, null); } } return(toReturn); }