typeof
有没有办法用泛型类型的表达式创建属性?
以下代码仅部分起作用:
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);