一,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. try catch 怎么写?

    除非必要,否则不在底层写try catch. 比如说,需要在catch里做一些处理,然后再抛出,一般不建议使用try catch掩盖程序出现的异常. try {     BuildQueryComma ...

  2. spark IDEA开发环境搭建及运行问题

    下图是例子: 还用说么,引入相关jar包(等下再一一说明)  包括scala,spark-assembly-1.4.1-hadoop2.5.0-cdh5.2.1.jar(按照你的spark和hadoo ...

  3. cf666 C. Codeword 组合数学 离线分块思想

                      time limit per test 6 seconds memory limit per test 256 megabytes input standard i ...

  4. CF 445A 简单DP

    今天早上找一道题的bug,还是找不出来,下午刷了几道水题,晚上准备回家的事, 然后本来想打CF的,一看,数学场,不打了. 这道题的题意: 给出一个序列,每次你可以从这个序列里面选择一个数ak,删除,然 ...

  5. [MySQL] 常用SQL的优化--18.4

    这里介绍下,Insert.Group By等SQL语句的优化方法: 1.大批量数据插入 当load命令导入数据的时候,可以进行适当的设置提高导入速度. 1.1 对于MyISAM表,可以先禁用非唯一索引 ...

  6. linux命令(9)设定固定ip

    一.使用命令设置ubuntu的ip地址 1.修改配置文件blacklist.conf禁用IPV6: sudo vi /etc/modprobe.d/blacklist.conf 2.在文档最后添加 b ...

  7. linux命令(2):df 磁盘占用

    在这里先讲讲linux命令df的资料: df 命令: linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信 ...

  8. java位运算

    Java的位运算(bitwise operators)直接对整数类型的位进行操作,这些整数类型包括long.int.short.char和 byte,位运算符具体如下表: 运算符 说明 << ...

  9. code md5

    using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptograph ...

  10. Java基础-布局