读书人

C#中Attribute属性Attribute属性,该

发布时间: 2012-07-31 12:33:47 作者: rapoo

C#中Attribute属性,Attribute属性
C#中Attribute属性,哪位有好的总结没???C#中Attribute一般用在哪些地方,有网址的,多贴几个,谢谢了!


[解决办法]
用于为反射提供元数据信息。
[解决办法]
这东西无法总结,也不要总结。

如同你不会去总结究竟你会用哪些单词组合作为你的变量名,或者.NET库中一共有多少个方法一样。这东西就像天上的星星数不清。
[解决办法]

C# code
 /// <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;        }    } 

读书人网 >C#

热点推荐