如何创建自己的c#属性? [英] How to create my own c# attributes?
问题描述
MVC验证器,如必填字段等......它们是c#属性吗?
我正在学习C#属性,我有一个疑问,MVC验证器是否是属性的例子或不 ?我认为它们是。
因为我学到了属性是为了元素的描述。我们可以创建自定义属性,可以为元素(方法,类等)提供描述。根据我的理解,这是属性的用户。那是对的吗?属性是否还有其他用途?
如果MVC要求提交验证器是一个属性,它是如何工作的?我的意思是代码是如何在atribute中编写的。它不仅仅是提供帮助信息,那么它是如何工作的?
MVC validators like required field etc..are they c# attributes?
I was learning C# attributes, I have one doubt that whether MVC validators are example of attributes or not ? I think they are.
As i learned attributes are for description of element. We can create custom attributes which can give description for a element(method,class etc.) This is the us of attributes as per my understanding. Is that correct? Is there any other use for attributes?
If MVC require filed validator is a attribute how does that works? i mean how the code has written in atribute.It is doing more than providing help information so how is that works ?
推荐答案
您可以创建自己的自定义属性。通常,数据注释是根据您的需求定制的。
尝试
^ ]
ASP.NET MVC自定义比较数据注释与客户端验证 [ ^ ]
MVC 4:Custom验证数据注释属性 [ ^ ]
You can create your own custom attributes. Generally, data annotations are customized to suit your needs.
Try
Custom Validation Attribute in ASP.NET MVC3[^]
ASP.NET MVC Custom Compare Data Annotation with Client Validation[^]
MVC 4: Custom Validation Data Annotation Attribute[^]
这篇关于如何创建自己的c#属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!