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的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...
随机推荐
- 数据库随机取n条记录
SQL Server SELECT TOP N * FROM 表名 ORDER BY NEWID() My SQL SELECT * FROM 表名 ORDER BY RAND() ...
- smartgit document Rebase
The Rebase command allows you to apply commits from one branch to another. Rebase can be viewed as m ...
- codeforces 258C Little Elephant and LCM 组合数学 枚举
题意: input : n a1,a2,...,an 1 <= n <= 10^5 1 <= ai <= 10^5 求b数组的方案数,b数组满足: 1. 1 <= bi ...
- 实现图片的2次缩放后再进行candy边缘检测
//实现图片的2次缩放后再进行candy边缘检测//Author:SD//Date:2015-9-27#include "cv.h"#include "highgui.h ...
- android:gravity 和 android:layout_Gravity属性
LinearLayout有两个非常相似的属性: android:gravity 与android:layout_gravity. 他们的区别在于: android:gravity 属性是对该view中 ...
- Bugtags:移动时代首选 Bug 管理系统
Bug 管理系统之重 回想我们每次开启一个新项目,筹备之初,首要之事就是选择一款 Bug 管理系统.市面上有诸多 Bug 管理系统可供选择:Jira.Redmine.Bugzilla 等.这些系统功能 ...
- Performance plugin离线安装
Upload安装plugin Upload安装plugin方式,需要手动下载plugin,然后在Jenkins界面中upload plugin,从而实现安装plugin的目的. 进入Jenkins界面 ...
- 日期选择控件-laydate
laydate控件非常简单易用,只需要调用一个个函数就可以轻松实现日期时间选择. <%@ page language="java" import="java.uti ...
- SQL字符串分组聚合(分组后的数据查询后用逗号隔开)
)) , 'aa') , 'bb') , 'aaa') , 'bbb') , 'ccc') go , , '') from tb group by id
- Delphi 线程的处理
http://www.cnblogs.com/doit8791/archive/2012/05/16/2502671.html