.net attribute 设置获取方法
来源:互联网 发布:怎么淘宝号 编辑:程序博客网 时间:2024/05/16 23:43
//备忘,忘性太大
namespace AttributeTest
{
class Program
{
static void Main(string[] args)
{
Person ps = new Person();
ps.Id = 1;
ps.Name = "23432";
ps.Credit = 234324234M;
Type t = ps.GetType();
foreach (var item in t.GetProperties())
{
if (t.GetProperty(item.Name).GetValue(ps, null) != null)
{
var a = Attribute.GetCustomAttributes(item);
foreach (var p in a)
{
if (p.GetType() == typeof(DBNameAttribute))
{
var b = (DBNameAttribute)p;
Console.WriteLine(b.DBName);
}
}
}
}
Console.ReadLine();
}
}
class Person
{
[DBName("ID")]
public int? Id { get; set; }
[DBName("Credit")]
public decimal? Credit { get; set; }
[DBName("PERSON_NAME")]
public string Name { get; set; }
public Person()
{
Id = null;
Credit = null;
}
}
}
namespace AttributeTest
{
class Program
{
static void Main(string[] args)
{
Person ps = new Person();
ps.Id = 1;
ps.Name = "23432";
ps.Credit = 234324234M;
Type t = ps.GetType();
foreach (var item in t.GetProperties())
{
if (t.GetProperty(item.Name).GetValue(ps, null) != null)
{
var a = Attribute.GetCustomAttributes(item);
foreach (var p in a)
{
if (p.GetType() == typeof(DBNameAttribute))
{
var b = (DBNameAttribute)p;
Console.WriteLine(b.DBName);
}
}
}
}
Console.ReadLine();
}
}
class Person
{
[DBName("ID")]
public int? Id { get; set; }
[DBName("Credit")]
public decimal? Credit { get; set; }
[DBName("PERSON_NAME")]
public string Name { get; set; }
public Person()
{
Id = null;
Credit = null;
}
}
}
0 0
- .net attribute 设置获取方法
- .net c#获取自定义Attribute
- .NET(C#):获取方法返回值的自定义特性(Attribute)
- 【TIP_3】在代码中获取attribute值的方法
- jdom中使用setAttribute(Attribute attribute)方法设置属性的注意事项
- .net 反射,通过自定义Attribute动态调用类方法
- .NET获取根目录方法
- Attribute属性设置
- .NET ATTRIBUTE 参考连接
- .net中属性Attribute
- .net中的Attribute,C#
- .NET中Attribute
- .net基础扫盲-Attribute
- .Net 特性(Attribute)
- .net 自定义attribute使用
- magento, 根据attribute code获取attribute value
- .net中获取或设置用户自定义控件值的方法
- .NET 获取路径方法总结
- 探讨下C++中的数组和指针的区别
- 项目日志文件存放位置
- Android Activity间传递数据
- think python学习心得-(4)有返回函数
- (转)git相关的基本操作都在此篇
- .net attribute 设置获取方法
- Opencv imread 不能正常读取
- 丘比龙的女神
- Matlab的BwLabel实现
- Java学习之Iterator(迭代器)的一般用法
- 深入解读Quartz的原理
- pycnn xor实例
- Spring Cron Expression
- (转)探索 .git 目录,让你真正了理解git