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的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...
随机推荐
- Exception error message with incorrect line number
In Release mode the number in front of the exception is NOT the line of code. Instead it's an offset ...
- Objective-C语法汇总
1.方法前的加减号 Objective-C中是没有public与private的概念的,即可以认为全部都是public.减号表示的是一个函数.方法.消息的开始.加号则表示不需要创建一个类的实例,其他类 ...
- PLSQL_性能优化系列19_Oracle Explain Plan解析计划通过Profile绑定
20150529 Created By BaoXinjian
- PLSQL_性能优化系列05_Oracle Hint提示
2014-06-20 Created By BaoXinjian
- OAF_VO系列4 - Row Imp的分析(概念)
20150706 Created By BaoXinjian
- Restful风格的简单实现办法
如果实在着急上Restful的URL在项目里 , 可以使用turkey的urlrewrite. 先在web.xml中加入如下代码 <!-- URL ReWrite --> <filt ...
- JAVA 静态代码块
特点:随着类的加载而执行,并且只会执行一次,并且还优先于主函数.作用,用于给类进行初始化 /* 静态代码块 格式: static{ 静态代码块中的执行语句 } 特点:随着类的加载而执行,并且只会执行一 ...
- linux下shell脚本学习
在Linux系统中,虽然有各种各样的图形化接口工具,但是sell仍然是一个非常灵活的工具.Shell不仅仅是命令的收集,而且是一门非常棒的编程语言.您可以通过使用shell使大量的任务自动化,shel ...
- (Delphi) Windows 32 API程序设计目录
这里所有程序均使用Delphi调用Windows 32 API方式实现,并不是使用VCL已经封装好的类实现的! (一)第一个窗口程序 01 创建第一个窗口.
- [Flex] IFrame系列 —— IFrame嵌入html后Alert弹出窗口被IFrame遮挡问题
<?xml version="1.0" encoding="utf-8"?> <!--- - - - - - - - - - - - - - ...