Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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# 更改内容属性_C#_Attributes_Data Annotations - Fatal编程技术网

C# 更改内容属性

C# 更改内容属性,c#,attributes,data-annotations,C#,Attributes,Data Annotations,我想创建一个属性来更改属性的内容 [CleanContent] public string address {get;set;} address = "hello world "; address would change to "hello world" 我使用过ValidationAttribute,有人知道我是否可以获取属性可以做到这一点吗?属性不是“活动的”-它们只是元数据,不做任何事情,除非一些调用框架通过反射检查它们,然后故意对它们调用方法。所以不,你不能这么做 警告:像po

我想创建一个属性来更改属性的内容

[CleanContent]
public string address {get;set;}

address = "hello world   ";
address would change to "hello world"
我使用过ValidationAttribute,有人知道我是否可以获取属性可以做到这一点吗?

属性不是“活动的”-它们只是元数据,不做任何事情,除非一些调用框架通过反射检查它们,然后故意对它们调用方法。所以不,你不能这么做


警告:像post sharp这样的IL重写工具也使用属性,但它们的行为方式非常不同(通过使用属性帮助它在编译后重新编写IL)。

您可以使用属性来标记要清理的属性,但它们自己不会清理,您需要调用它们

下面是一个与您的问题密切相关的问题,它提供了一些想法: