2016-08-01 9 views
-1

でクラスを定義は私の作品次のクラス定義を持つ汎用型

public class Envelope<T> { } 

私は次のことを試してみました:

public class AsyncValidationRequestHandler<TRequest, TResponse> : IAsyncRequestHandler<TRequest, TResponse> 
    where TRequest : IAsyncRequest<TResponse> 
    where TResponse : Envelope<TModel> { } 

基本的に、私は次のようにエンベロープを定義します:

ModalA modelA = new ModelA(); 
Envelope<ModelA> envelopeA = new Envelope<ModelA>(); 

または

ModalB modelB = new ModelB(); 
Envelope<ModelB> envelopeB = new Envelope<ModelB>(); 

そして、私は私の回答は、常に何かの封筒である知っている...

しかし、私のコードはコンパイルされません。エラーが表示されます:

The type or namespace name 'TModel' could not be found (are you missing a using directive or an assembly reference?)  

解決方法インターフェイスが必要ですか?

+0

'' TModel''がここ何ですか? –

+0

実際にあなたのスニペットにここに表示されているような 'EnvelopeTModel>'の左角括弧がありませんか?それがコンパイルされないようにするメッセージは正確には何ですか? – Zack

+0

@EhsanSajjad TModelはジェネリック型です –

答えて

4

あなたも、一般的なパラメータとしてTModelを宣言する必要があります。

public class AsyncValidationRequestHandler<TRequest, TResponse, TModel> : IAsyncRequestHandler<TRequest, TResponse> 
    where TRequest : IAsyncRequest<TResponse> 
    where TResponse : Envelope<TModel> { } 
関連する問題