相关疑难解决方法(0)

两个属性在语义上相同的TypeIds是不同的还是相同的?

MSDN声明该属性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
{
}
Run Code Online (Sandbox Code Playgroud)

我应该将TypeId实现为

        get
        {
            return (object)this; //TypeId identifies every individual instance of the attribute
        }
Run Code Online (Sandbox Code Playgroud)

要么

        get
        {
            return (object)MaxVolume; //If we compare two AmpVolume attributes, they should be the same if the …
Run Code Online (Sandbox Code Playgroud)

.net c# reflection typeid

5
推荐指数
1
解决办法
916
查看次数

标签 统计

.net ×1

c# ×1

reflection ×1

typeid ×1