Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 可以使用PostSharp AOP注入动态代码_C#_Attributes_Aop_Postsharp - Fatal编程技术网

C# 可以使用PostSharp AOP注入动态代码

C# 可以使用PostSharp AOP注入动态代码,c#,attributes,aop,postsharp,C#,Attributes,Aop,Postsharp,假设我创建了一个自定义的PS属性InjectCodeAttribute,并将其应用于一个类或类成员,那么是否可以告诉PostSharp使用作为字符串提供的动态C#代码替换该属性 例如,我是否可以将其转换为: [InjectCodeAttribute] 公共类MyClass 为此: [DependencyProperty,混淆(Feature=“renaming”,Exclude=true,stripAfter混淆=true)] 公共类MyClass 通过向InjectCodeAttribute属

假设我创建了一个自定义的PS属性
InjectCodeAttribute
,并将其应用于一个类或类成员,那么是否可以告诉PostSharp使用作为字符串提供的动态C#代码替换该属性

例如,我是否可以将其转换为:

[InjectCodeAttribute]
公共类MyClass

为此:

[DependencyProperty,混淆(Feature=“renaming”,Exclude=true,stripAfter混淆=true)]
公共类MyClass

通过向
InjectCodeAttribute
属性提供此字符串
[DependencyProperty,Obfuscation(Feature=“rename”,Exclude=true,StripAfterObfuscation=true)]


注意:我知道PostSharp提供的自定义属性功能,我可以创建一个注入示例属性的属性,但我只想知道是否可以注入任何代码(即使是在编译期间可能引发异常/错误的无效代码)我以字符串形式提供。

对于所描述的用例,答案是否定的。PostSharp在C#编译完成后运行,并处理二进制程序集。现在为C#编译器添加字符串输入已经太晚了