一,Attributes 类新建一个子类,DetailAttributes
二, 在类的属性声明上面加Attributes
  1. public class testAttributes
  2. {
  3. [Detail(AttrName = "宽度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
  4. public string username {get;set;}
  5.  
  6. public class FactoryDetail
  7. {
  8. [Detail(AttrName = "宽度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
  9. public string Width { set; get; }
  10.  
  11. [Detail(AttrName = "高度", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
  12. public string Height { set; get; }
  13.  
  14. [Detail(AttrName = "状态", Html = "<select></select>", DefaultValue = null, DataSource = "select text,value from status")]
  15. public string Status { set; get; }
  16.  
  17. [Detail(AttrName = "Tag值", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
  18. public string Tag { set; get; }
  19. [Detail(AttrName = "描述", Html = "<input type='text' />", DefaultValue = "", DataSource = null)]
  20. public string Desc { set; get; }
  21.  
  22. public string test()
  23. {
  24. string s = "";
  25. Type oType = this.GetType();
  26. foreach (PropertyInfo opi in oType.GetProperties())
  27. {
  28. object [] peratt = opi.GetCustomAttributes(true);
  29. foreach (var tmp in peratt)
  30. {
  31. if (tmp.GetType() == typeof(FactoryDetail))
  32. {
  33. DetailAttribute detailAtt = (DetailAttribute)tmp;
  34.  
  35. s += "AttrName: " + detailAtt.AttrName + " ";
  36. }
  37. }
  38. }
  39. return s;
  40. }
  41. }
  42. }

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. 数据库随机取n条记录

    SQL Server SELECT TOP N  *  FROM  表名  ORDER BY  NEWID() My SQL  SELECT  *  FROM  表名 ORDER BY RAND() ...

  2. smartgit document Rebase

    The Rebase command allows you to apply commits from one branch to another. Rebase can be viewed as m ...

  3. codeforces 258C Little Elephant and LCM 组合数学 枚举

    题意: input : n a1,a2,...,an 1 <= n <= 10^5 1 <= ai <= 10^5 求b数组的方案数,b数组满足: 1. 1 <= bi ...

  4. 实现图片的2次缩放后再进行candy边缘检测

    //实现图片的2次缩放后再进行candy边缘检测//Author:SD//Date:2015-9-27#include "cv.h"#include "highgui.h ...

  5. android:gravity 和 android:layout_Gravity属性

    LinearLayout有两个非常相似的属性: android:gravity 与android:layout_gravity. 他们的区别在于: android:gravity 属性是对该view中 ...

  6. Bugtags:移动时代首选 Bug 管理系统

    Bug 管理系统之重 回想我们每次开启一个新项目,筹备之初,首要之事就是选择一款 Bug 管理系统.市面上有诸多 Bug 管理系统可供选择:Jira.Redmine.Bugzilla 等.这些系统功能 ...

  7. Performance plugin离线安装

    Upload安装plugin Upload安装plugin方式,需要手动下载plugin,然后在Jenkins界面中upload plugin,从而实现安装plugin的目的. 进入Jenkins界面 ...

  8. 日期选择控件-laydate

    laydate控件非常简单易用,只需要调用一个个函数就可以轻松实现日期时间选择. <%@ page language="java" import="java.uti ...

  9. SQL字符串分组聚合(分组后的数据查询后用逗号隔开)

    )) , 'aa') , 'bb') , 'aaa') , 'bbb') , 'ccc') go , , '') from tb group by id

  10. Delphi 线程的处理

    http://www.cnblogs.com/doit8791/archive/2012/05/16/2502671.html