读书人

这几行代码是什么意思?解决思路

发布时间: 2012-04-23 13:17:38 作者: rapoo

这几行代码是什么意思?
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class AttachDataAttribute : Attribute
{
public AttachDataAttribute(object key, object value)
{
this.Key = key;
this.Value = value;
}

public object Key { get; private set; }

public object Value { get; private set; }
}

public static class AttachDataExtensions
{
public static object GetAttachedData(
this ICustomAttributeProvider provider, object key)
{
var attributes = (AttachDataAttribute[])provider.GetCustomAttributes(
typeof(AttachDataAttribute), false);
return attributes.First(a => a.Key.Equals(key)).Value;
}

public static T GetAttachedData<T>(
this ICustomAttributeProvider provider, object key)
{
return (T)provider.GetAttachedData(key);
}

public static object GetAttachedData(this Enum value, object key)
{
return value.GetType().GetField(value.ToString()).GetAttachedData(key);
}

public static T GetAttachedData<T>(this Enum value, object key)
{
return (T)value.GetAttachedData(key);
}
}
请帮忙给这几行代码加上注释

[解决办法]
百度搜索“C#特性”
[解决办法]
特性,属性,泛型,继承,接口
[解决办法]
自定义特性
[解决办法]
自定义

读书人网 >C#

热点推荐