【发布时间】:2011-06-29 01:47:23
【问题描述】:
我有以下通用类,它们处理返回不同类型对象的请求:
class Request<T> {
/* ... */
public T Result { get; protected set; }
public abstract bool Execute();
protected bool ExecuteCore(params /* ... */) { /* ... */ }
}
class ObjectRequest<T> : Request<T>
where T : class, new() { /* ... */ }
class ListRequest<T> : Request<List<T>>
where T : class, new() { /* ... */ }
class CompoundRequest<T, U> : Request<T>
where T : class, IHeader<U>, new()
where U : class, new() { /* ... */ }
class CompoundRequest<T, U, V> : Request<T>
where T : class, IHeader<U>, IHeader<V>, IHeader<W>, new()
where U : class, new()
where V : class, new() { /* ... */ }
class CompoundRequest<T, U, V, W> : Request<T>
where T : class, IHeader<U>, IHeader<V>, new()
where U : class, new()
where V : class, new()
where W : class, new() { /* ... */ }
interface IHeader<T> {
List<T> Details { get; set; }
}
现在我想创建一个类来处理返回 no 对象的请求。但是,不允许将泛型参数设置为 null:
class NoReturnRequest : Request<void> { /* ... */ } // illegal
我该如何解决这个问题?
【问题讨论】: