[ConfigurationProperty(“providers”)] 是做什么的?
我正在阅读这篇关于提供商模式的文章。请指导我这个陈述是什么:
[ConfigurationProperty("providers")]
实际上我想了解什么是 [] ?我还在网络方法上看到了这样一行带有[]的内容。 []是什么?有什么用?我什至不知道要搜索什么我应该命名它?请指导和帮助我。
谢谢
I am reading this article on provider patren. Kindly guide me what do this statement:
[ConfigurationProperty("providers")]
Actually I want to learn what is [] ? I also saw such a line on web methods with []. What are [] ? what is there use ? I am even not aware to search what I should name it ? plz guide and help me.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[Foo(bla)]
是属性的语法 - 有关某些类型或成员(甚至程序集本身;或者实际上是参数)的附加元数据。您可以编写自己的属性,例如,属性如下:名称
Attribute
是推断出来的,因此只需要[ConfigurationProperty]
。字符串"providers"
用作构造函数参数,您也可以使用属性赋值,例如:查找类型
FooAttribute
或Foo
,带有一个采用int
和string
的构造函数,并具有一个可以分配int
的属性Bar
代码>.大多数属性不会直接执行任何操作,但您可以编写代码来检查属性类型(通过反射),这是库代码了解如何执行操作的一种非常方便的方法。使用类型。
例如:
这会重新配置
XmlSerializer
(检查上述属性)以将类型序列化为:如果没有属性,则为:
[Foo(bla)]
is the syntax for an attribute - additional metadata about some type or member (or even the assembly itself; or indeed parameters). You can write your own attributes, for example that one is something like:the name
Attribute
is inferred, so only[ConfigurationProperty]
is needed. The string"providers"
is used as a constructor argument, and also you can use property assignments, for example:looks for a type
FooAttribute
orFoo
, with a constructor that takes anint
and astring
, and has a propertyBar
that can be assigned anint
.Most attributes don't do anything directly, but you can write code that inspects types for attributes (via reflection), which is a very convenient way of library code knowing how to work with a type.
For example:
this reconfigures
XmlSerializer
(which checks for the above attributes) to serialize the type as:where without the attributes it would be:
如果您正在编写一些内容来从 Web 或应用程序 .config 读取设置,则可以创建一个配置部分。这就是声明
ConfigurationProperty
的用武之地。查看 http://msdn.microsoft.com/en-us/library/system.configuration.configurationpropertyattribute(v=VS.100).aspx
If you are writing something to read settings from the web or app .config, you can create a configuration section. This is where declaring the
ConfigurationProperty
comes in.Check out http://msdn.microsoft.com/en-us/library/system.configuration.configurationpropertyattribute(v=VS.100).aspx