C# 特性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 和反射的更多相关文章
- C#中的定制特性(Attributes)
C#中的定制特性(Attributes) 介绍 Attributes是一种新的描述信息,我们既可以使用attributes来定义设计期信息(例如:帮助文件.文档的URL),还可能用attributes ...
- C#反射与特性(一):反射基础
目录 C#反射与特性(一):反射基础 1. 说明 1.1 关于反射.特性 2. 程序集操作 2.1 获取 程序集对象(Assembly) 2.2 Assembly 使用 2.3 获取程序集的方式 C# ...
- C#中的特性(Attributes)
约定: 1.”attribute”和”attributes”均不翻译 2.”property”译为“属性” 3.msdn中的原句不翻译 4.”program entity”译为”语言元素” Attri ...
- 特性(Attributes)
用以将元数据或声明信息与代码(程序集.类型.方法.属性等)相关联.特性与程序实体相关联后,即可在运行时用反射技术查询特性. 例如,在一个方法前标注[Obsolete]特性,则调用该方法时VS则会提示该 ...
- unity中的[xxxxxx]特性(Attributes)
[SerializeField] 在Inspector版面中显示非public属性,并且序列化:若写在public前面,等于没写. [Obsolete("调用提示信息")] [No ...
- C#反射与特性(三):反射类型的成员
目录 1,获取类型的信息 1.1 类型的基类和接口 1.2 获取属性.字段成员 上一篇文章中,介绍如何获取 Type 类型,Type 类型是反射的基础. 本篇文章中,将使用 Type 去获取成员信息, ...
- Attributes(1):反射Attribute并输出
using System; using System.Reflection; using System.Text; namespace Attribute01 { class Program { ...
- C#图解教程 第二十四章 反射和特性
反射和特性 元数据和反射Type 类获取Type对象什么是特性应用特性预定义的保留的特性 Obsolete(废弃)特性Conditional特性调用者信息特性DebuggerStepThrough 特 ...
- EF+LINQ事物处理 C# 使用NLog记录日志入门操作 ASP.NET MVC多语言 仿微软网站效果(转) 详解C#特性和反射(一) c# API接受图片文件以Base64格式上传图片 .NET读取json数据并绑定到对象
EF+LINQ事物处理 在使用EF的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...
随机推荐
- bug_ _fragment_“The specified child already has a parent. You must call removeView"的解决以及产生的原因
这个异常的出现往往是因为非法使用了某些方法引起的. 从字面意思上是说这个特定的child已经有一个parent了,你必须在这个parent中首先调用removeView()方法,才能继续你的内容.这里 ...
- 在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现Web端直传,服务端签名直传并设置上传回调的实现流程
在OneThink(ThinkPHP3.2.3)中整合阿里云OSS的PHP-SDK2.0.4,实现本地文件上传流程 by shuijingwan · 2016/01/13 1.SDK安装 github ...
- ethereal抓包工具
ethereal是目前网络上开源的一款功能强大的以太网抓包工具,该软件可以监听异常封包,检测软件封包问题,从网络上抓包,并且能对数据包进行分析,从而帮助用户解决各种网络故障,更加方便查看.监控TCP ...
- ubuntu 配置TFTP和NFS
1.安装软件包 sudo apt-get install tftpd tftp xinetd 2.建立配置文件 在/etc/xinetd.d/下建立一个配置文件tftp sudo vi /etc/xi ...
- linux内核设计与实现--进程调度 系统调用
进程可以分为I/O消耗型和处理器消耗型. I/O消耗型指,进程的大部分时间用来提交I/O请求或者等待I/O请求. 处理器耗费型进程把时间大多用在执行代码上. linux采用了两种不同的优先级范围: 第 ...
- [Flex] IFrame系列 —— 在flex的web应用中嵌入html的方法
在flex的web应用中,我们往往必须有嵌入html的需求,这时候你会发现IFrame很有用! flex而且可以和html中的JavaScript进行交互,flex可以通过iframe调用到html中 ...
- Dynamics CRM 2011 权限管理(转)
http://www.cnblogs.com/LeoTang/p/3344265.html Dynamics CRM 2011 权限管理 CRM系统基于角色的权限主要通过部门.角色.用户.团队来 进行 ...
- text透明无边框
<input type="text" style="border:0px;background-color:transparent;outline:none;&qu ...
- 查看django里所有的url
>>> from django.core.urlresolvers import get_resolver >>> get_resolver(None).rever ...
- [SQL] 不知道是什么存储过程
CREATE PROCEDURE dt_DXS_STAFF_ACTIVE @STAFFSTATUS INT, @STAFFNUM INT, @STARTNO INT, @@TOTALCOUNT INT ...