class Logger : ILogger, IStartable {}
///use
new FluentBuilder<Logger>().As<ILogger>().As<IStartable>();
这表明了我的意图,但不起作用(因为它在语法上并不错误):
public class FluentBuilder<TService> where TService : class
{
public FluentBuilder<TService> As<TContract>() where TService : TContract
{
return this;
}
}
public static class Ex
{
public static FluentBuilder<TService> As<TService, TContract>(this FluentBuilder<TService> that)
where TContract : class
where TService : class, TContract
{
return that;
}
}
使用语法如下:
new FluentBuilder<Logger>().As<Logger, ILogger>().As<Logger, IStartable>();