private static object BuildConsumer(Func<object> consumerFactory, Type messageType, Lifestyle? lifestyle)
{
Type consumerType;
switch (lifestyle)
{
case null:
case Lifestyle.Normal:
return consumerFactory();
case Lifestyle.Lazy:
consumerType = typeof(LazyConsumerOf<>).MakeGenericType(messageType);
return Activator.CreateInstance(consumerType, consumerFactory);
case Lifestyle.Delegated:
consumerType = typeof(FactoryConsumerOf<>).MakeGenericType(messageType);
return Activator.CreateInstance(consumerType, consumerFactory);
default:
throw new ConfigurationErrorsException("Unknown or unsupported consumer lifestyle : [{0}].".FormatEx(lifestyle));
}
}