/// <summary>
/// Create a factory generator.
/// </summary>
/// <param name="productRegistration">The component that will be activated in
/// order to create the products of the factory.</param>
/// <param name="delegateType">The delegate to provide as a factory.</param>
/// <param name="parameterMapping">The parameter mapping mode to use.</param>
public FactoryGenerator(Type delegateType, IComponentRegistration productRegistration, ParameterMapping parameterMapping)
{
if (productRegistration == null)
{
throw new ArgumentNullException("productRegistration");
}
Enforce.ArgumentTypeIsFunction(delegateType);
_generator = CreateGenerator((activatorContextParam, resolveParameterArray) =>
{
// productRegistration, [new Parameter(name, (object)dps)]*
var resolveParams = new Expression[] {
Expression.Constant(productRegistration, typeof(IComponentRegistration)),
Expression.NewArrayInit(typeof(Parameter), resolveParameterArray)
};
// c.Resolve(...)
return(Expression.Call(
activatorContextParam,
ReflectionExtensions.GetMethod <IComponentContext>(cc => cc.ResolveComponent(default(IComponentRegistration), default(Parameter[]))),
resolveParams));
},
delegateType,
GetParameterMapping(delegateType, parameterMapping));
}