一,Attributes 类新建一个子类,DetailAttributes
二, 在类的属性声明上面加Attributes
public class testAttributes
{
[Detail(AttrName = "宽度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
public string username {get;set;} public class FactoryDetail
{
[Detail(AttrName = "宽度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
public string Width { set; get; } [Detail(AttrName = "高度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
public string Height { set; get; } [Detail(AttrName = "状态", Html = "<select></select>", DefaultValue = null, DataSource = "select text,value from status")]
public string Status { set; get; } [Detail(AttrName = "Tag值", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
public string Tag { set; get; }
[Detail(AttrName = "描述", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
public string Desc { set; get; } public string test()
{
string s = "";
Type oType = this.GetType();
foreach (PropertyInfo opi in oType.GetProperties())
{
object [] peratt = opi.GetCustomAttributes(true);
foreach (var tmp in peratt)
{
if (tmp.GetType() == typeof(FactoryDetail))
{
DetailAttribute detailAtt = (DetailAttribute)tmp; s += "AttrName: " + detailAtt.AttrName + " ";
}
}
}
return s;
}
}
}

C# 特性Attributes 和反射的更多相关文章

  1. C#中的定制特性(Attributes)

    C#中的定制特性(Attributes) 介绍 Attributes是一种新的描述信息,我们既可以使用attributes来定义设计期信息(例如:帮助文件.文档的URL),还可能用attributes ...

  2. C#反射与特性(一):反射基础

    目录 C#反射与特性(一):反射基础 1. 说明 1.1 关于反射.特性 2. 程序集操作 2.1 获取 程序集对象(Assembly) 2.2 Assembly 使用 2.3 获取程序集的方式 C# ...

  3. C#中的特性(Attributes)

    约定: 1.”attribute”和”attributes”均不翻译 2.”property”译为“属性” 3.msdn中的原句不翻译 4.”program entity”译为”语言元素” Attri ...

  4. 特性(Attributes)

    用以将元数据或声明信息与代码(程序集.类型.方法.属性等)相关联.特性与程序实体相关联后,即可在运行时用反射技术查询特性. 例如,在一个方法前标注[Obsolete]特性,则调用该方法时VS则会提示该 ...

  5. unity中的[xxxxxx]特性(Attributes)

    [SerializeField] 在Inspector版面中显示非public属性,并且序列化:若写在public前面,等于没写. [Obsolete("调用提示信息")] [No ...

  6. C#反射与特性(三):反射类型的成员

    目录 1,获取类型的信息 1.1 类型的基类和接口 1.2 获取属性.字段成员 上一篇文章中,介绍如何获取 Type 类型,Type 类型是反射的基础. 本篇文章中,将使用 Type 去获取成员信息, ...

  7. Attributes(1):反射Attribute并输出

    using System; using System.Reflection; using System.Text;   namespace Attribute01 { class Program { ...

  8. C#图解教程 第二十四章 反射和特性

    反射和特性 元数据和反射Type 类获取Type对象什么是特性应用特性预定义的保留的特性 Obsolete(废弃)特性Conditional特性调用者信息特性DebuggerStepThrough 特 ...

  9. EF+LINQ事物处理 C# 使用NLog记录日志入门操作 ASP.NET MVC多语言 仿微软网站效果(转) 详解C#特性和反射(一) c# API接受图片文件以Base64格式上传图片 .NET读取json数据并绑定到对象

    EF+LINQ事物处理   在使用EF的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...

随机推荐

  1. 探秘JavaScript中的六个字符

    JavaScript 是一个奇怪而有趣的语言,我们可以写一些疯狂却仍然有效的代码.它试图帮助我们把事情转换到基于我们如何对待他们的特定类型. 如果我们添加一个字符串,JavaScript会假定我们希望 ...

  2. ibatis插入数据后返回自增长的主键

    insert into testTable ( activity_id,activity_title values ( #{activityId,jdbcType=INTEGER}, #{activi ...

  3. ubuntu 关机,重启,注销命令

    1关机命令 shutdown 好像ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令. 1)shutdown –hel ...

  4. Package 'chkconfig' has no installation candidate

    Chkcofig不再适用于Ubuntu系统,可用类似的软件sysv-rc-conf进行替换: Chkconfig is no longer available in Ubuntu. Chkconfig ...

  5. java学习_文件工具类

    工具类里面的方法全部都是静态的,调用的时候不需要实例化

  6. java异常处理机制throws

    throws可以在方法声明时抛出的异常.原则上throws声明的异常,一定要在该方法中抛出,否则没有意义. 相反的,若方法中我们主动通过throw抛出一个异常,应该在throws中声明该种类异常,通知 ...

  7. MongoDB 语法使用小结

    MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的     他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据 ...

  8. C++ DLL中导出函数的声明的方法

    定义: TESTDLLEXPORT_API int fnTestDllExport(void); TESTDLLEXPORT_API int fnTestCall(void); TESTDLLEXPO ...

  9. aix下oracle数据库创建表空间和用户

    #mklv -y lvname -T O -w n -s n -r n datavg 500 在两个节点分别修改如下权限: #chown -R oracle:oinstall /dev/rlvname ...

  10. C# 文件压缩与解压(ZIP格式)

    在企业开发过程中经常会遇到文件的压缩与解压,虽然网上很多流行的压缩文件格式都是RAR的,但是由于RAR不是一个开放的标准,因此ZIP成了更多人的选择.如果你不想自己开发的话可以选择开源的项目,比如Sh ...