3

結果のクラス宣言は次のようになります。

public sealed partial class Refund : DataObjectBase<Refund>
 {
}

}

このコード(抜粋):

targetClass = new CodeTypeDeclaration(className);
            targetClass.IsClass = true;
            targetClass.TypeAttributes =
                TypeAttributes.Public | TypeAttributes.Sealed;
            targetClass.IsPartial = true; //partial so that genn'ed code can be safely modified
            targetClass.TypeParameters.Add(new CodeTypeParameter{ Name=className});
            targetClass.BaseTypes.Add(new CodeTypeReference { BaseType = "DataObjectBase", Options = CodeTypeReferenceOptions.GenericTypeParameter });

次のクラス宣言を生成します。

public sealed partial class Refund<Refund> : DataObjectBase
 {
}

私は何を間違っていますか?

4

2 に答える 2

2

BaseType の次の文字列でうまくいくと思います (未テスト):

"DataObjectBase`1[[Refund]]"

Refund少なくともアセンブリ名を含めて、の完全修飾名を指定する必要がある場合があります。

"DataObjectBase`1[[Refund, RefundAssembly]]"

次に、行を削除する必要がありますtargetClass.TypeParameters.Add(...)

于 2009-08-28T17:13:51.563 に答える
1

式をCodeDOMに使用する場合、次のようになります。

var cls = Define.Class("Refund", 
   TypeAttributes.Public | TypeAttributes.Sealed, true)
   .Inherits(CodeDom.TypeRef("DataObjectBase","Refund"))
于 2009-09-22T10:00:29.027 に答える