【发布时间】:2012-01-13 16:26:09
【问题描述】:
MSDN states 的属性TypeId 表示:
在实现时,此标识符只是属性的类型。但是,唯一标识符旨在用于标识相同类型的两个属性。
然而,预期用途是区分单个属性实例(例如,与应用它们的类的不同实例相关联的那些实例)还是区分具有相同类型但由于其属性值在语义上不同的属性?
例如,假设我有以下内容:
public sealed class AmpVolume : System.Attribute
{
public int MaxVolume { get; set; }
public AmpVolume(int maxvolume)
{
MaxVolume = maxvolume;
}
}
[AmpVolume(11)]
public class SpinalTapGuitarAmp
{
}
[AmpVolume(11)]
public class SpinalTapBassAmp
{
}
[AmpVolume(10)]
public class RegularAmp
{
}
我应该将 TypeId 实现为
get
{
return (object)this; //TypeId identifies every individual instance of the attribute
}
或者
get
{
return (object)MaxVolume; //If we compare two AmpVolume attributes, they should be the same if the volume is the same, right?
}
【问题讨论】:
标签: c# .net reflection typeid