3
typeof
式をジェネリック型で作成する方法はありますか?ReSharper SDKで[CustomAttribute(typeof(GenericType <,>))]を作成するには?
次のコードは、部分的にしか機能します:
CSharpElementFactory factory = ...
IClassDeclaration typeDeclaration = ...
IClassDeclaration classDeclaration = ...
IType[] attributeTypeParameters =
(from typeParameter in classDeclaration.TypeParameters
select (IType)TypeFactory.CreateUnknownType(module)).ToArray();
IType classType = TypeFactory.CreateType(classDeclaration.DeclaredElement,
attributeTypeParameters);
var attribute = factory.CreateAttribute(
new SpecialAttributeInstance(
ClrTypeNames.ContractClassAttribute,
module,
() => new[] { new AttributeValue(classType) },
Enumerable.Empty<Pair<string, AttributeValue>>));
typeDeclaration.AddAttributeAfter(attribute, null);
'TypeElementUtil.GetTypeElementByClrName(someGenericClass、モジュール)に関連してクラスを装飾コードスニペットだ'ヌルです。したがって、TypeFactory.CreateType(someGenericTypeElement ...)は例外をスローします。 –
.Netのどのバージョンを使用していますか(つまり、プロジェクトの.Netフレームワークのターゲット) –
ターゲットフレームワークは4です(クライアントプロファイルではありません)。 –