C#中DefaultValueAttribute的使用
来源:互联网 发布:肖八肖四选择题 知乎 编辑:程序博客网 时间:2024/06/06 03:06
首先说明:
DefaultValueAttribute是指定属性 (Property) 的默认值。
命名空间:System.ComponentModel
程序集:System(在 system.dll 中)
比如我们这样写:
public class PrintInfo { [DefaultValue(typeof(string), "555")] public string UserName { get; set; } }那么要想得到这个555并不是用
string _UserName=new PrintInfo().UserName;而应该这样写:
AttributeCollection attrColl = TypeDescriptor.GetProperties(new PrintInfo())["UserName"].Attributes; DefaultValueAttribute attr = attrColl[typeof(DefaultValueAttribute)] as DefaultValueAttribute; string _Value = attr.Value;
这个时候_Value的值为555,如果用上面的方法得到的_UserName的值依然为NULL。具体我也说不明白,但是在一个属性上面加上这个Attribute,很会让人误解。
参见:http://msdn.microsoft.com/zh-cn/library/system.componentmodel.defaultvalueattribute(VS.80).aspx
- C#中DefaultValueAttribute的使用
- 令人疑惑的defaultValueAttribute
- JSON使用JsonIgnoreAttribute,ErrorHandlingAttribute,DefaultValueAttribute
- C# 中??的使用
- C#中[]的使用
- C#中?的使用
- c#中$的使用
- C#中参数的使用
- c#中DataList的使用
- c#中随机数的使用
- c#中工具条的使用
- C#中unsafe的使用
- c# 中颜色的使用
- C#中WebBrowser的使用
- C#中log4net的使用
- C#中using的使用
- C#中datetime的使用
- C#中Hashtable的使用
- “直来职往”观后感
- jdk中的设计模式之生成器模式(Builder)
- svn 服务器管理个人日记
- 【转】 图像处理与视觉计算的网络资源和一些评述
- java 集合ArrayList及LinkList源码分析
- C#中DefaultValueAttribute的使用
- uCos中优先级判定表OSUnMapTbl原理
- 如何实现iframe高度的自适应
- 2011面试题目之猴子偷桃
- android中的资源
- Android Path 使用
- 人人都能做的性能优化 web前端优化
- 线程1
- setLayout: Attempting to set QLayout "" on MainWindow "MainWindow", which already has a layout