怎样给类的属性的Attributes赋值????

bryht 2010-05-13 10:13:06
MyClass my=new MyClass();
也就是给my.GetType().GetProperties()[0].Attributes赋值

public class MyClass
{
[ColumnAttribute(IsPK=true)]//这样设置了取出的my.GetType().GetProperties()[0].Attributes为None
public int SID{get;set;}

public string Name{get;set;}
}

想问各位大侠,应该怎样给类的属性的Attributes赋值啊?????
...全文
354 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jerryfangsh 2010-05-13
  • 打赏
  • 举报
回复
使用

my.GetType().GetProperties()[0].GetCustomAttributes()[0]

获取自定义特性
jietuan 2010-05-13
  • 打赏
  • 举报
回复
你使用反射。
guanmingle 2010-05-13
  • 打赏
  • 举报
回复
MyClass.SID=0;
MyClass.Name="";
这个意思吗?
mngzilin 2010-05-13
  • 打赏
  • 举报
回复
my.GetType().GetCustomAttributes(typeof(ColumnAttribute), true)[0].
zzx509 2010-05-13
  • 打赏
  • 举报
回复
Attribute是类的元数据,这个也能被Set?
动态添加Attribute倒是做过,Set没有接触过。
bryht 2010-05-13
  • 打赏
  • 举报
回复
my.GetType().GetProperties()[0].Attributes取出的值为空?
在MyClass类的哪个地方设置能让它不为空?
我目前是这么设置的

[ColumnAttribute(IsPK=true)]
public int SID{get;set;}

但是不管用!

我就想问到底应该在MyClass这个类里怎么设置,在哪里设置,才能使我的MyClass的对象
my的my.GetType().GetProperties()[0].Attributes能取道我设置的值???
my

110,590

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧