/// <summary> /// Export as a specific type /// </summary> /// <param name="type">type to export as</param> /// <returns>configuraiton object</returns> public IFluentExportStrategyConfiguration As(Type type) { if (type == null) throw new ArgumentNullException(nameof(type)); _exportConfiguration.AddExportAs(type); return this; }
private void ProcessClassAttributes(IConfigurableActivationStrategy strategy) { foreach (var attribute in strategy.ActivationType.GetTypeInfo().GetCustomAttributes()) { var exportAttribute = attribute as IExportAttribute; var types = exportAttribute?.ProvideExportTypes(strategy.ActivationType); if (types != null) { foreach (var type in types) { strategy.AddExportAs(type); } } var conditionAttribute = attribute as IExportConditionAttribute; var condition = conditionAttribute?.ProvideCondition(strategy.ActivationType); if (condition != null) { strategy.AddCondition(condition); } var keyedTypeAttribute = attribute as IExportKeyedTypeAttribute; var tuple = keyedTypeAttribute?.ProvideKey(strategy.ActivationType); if (tuple != null) { strategy.AddExportAsKeyed(tuple.Item1, tuple.Item2); } } }
/// <summary> /// Export as a specific type /// </summary> /// <param name="type">type to export as</param> /// <returns>configuration object</returns> public IFluentExportStrategyConfiguration As(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (type.GetTypeInfo().IsGenericTypeDefinition&& !_exportConfiguration.ActivationType.GetTypeInfo().IsGenericTypeDefinition) { throw new ArgumentException("Exported type is not open generic but As type is open"); } _exportConfiguration.AddExportAs(type); return(this); }
/// <summary> /// Export as specific type /// </summary> /// <param name="type">type to export as</param> /// <returns></returns> public IFluentExportInstanceConfiguration <T> As(Type type) { _exportConfiguration.AddExportAs(type); return(this); }