C#中Attribute属性,Attribute属性

章子宝 2011-09-16 07:23:58
C#中Attribute属性,哪位有好的总结没???C#中Attribute一般用在哪些地方,有网址的,多贴几个,谢谢了!
...全文
157 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
myceolzy 2011-09-16
  • 打赏
  • 举报
回复

/// <summary>
/// 属性赋值
/// </summary>
/// <typeparam name="T">目标属性</typeparam>
public static class MyProperty<T>
{
public static T PropertyCopy(object source, T target)
{
Type sourceType = source.GetType();
Type targetType = target.GetType();
PropertyInfo[] pis = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo pi in pis)
{
string propertyName = pi.Name;
PropertyInfo pit = targetType.GetProperty(propertyName);
if (pit != null)
{
pit.SetValue(target, pi.GetValue(source, null), null);
}
}
return target;
}
}
threenewbee 2011-09-16
  • 打赏
  • 举报
回复
这东西无法总结,也不要总结。

如同你不会去总结究竟你会用哪些单词组合作为你的变量名,或者.NET库中一共有多少个方法一样。这东西就像天上的星星数不清。
threenewbee 2011-09-16
  • 打赏
  • 举报
回复
这东西无法总结、不需要总结。

如同你不能总结出你写一个程序究竟使用哪些单词作为变量名。你也不会总结.NET库中究竟提供了多少个函数。这就像天上的星星一样多。
threenewbee 2011-09-16
  • 打赏
  • 举报
回复
用于为反射提供元数据信息。

111,092

社区成员

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

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

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