2
我有以下的自定義屬性:可以在編譯時評估C#自定義屬性嗎?
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
sealed public class CLSASafeAttribute : Attribute
{
public Boolean CLSSafe { get; set; }
public CLSASafeAttribute(Boolean safe)
{
CLSSafe = safe;
}
}
而下面的枚舉部分:
public enum BaseTypes
{
/// <summary>
/// Base class.
/// </summary>
[CLSASafe(true)]
Object = 0,
/// <summary>
/// True/false.
/// </summary>
[CLSASafe(true)]
Boolean,
/// <summary>
/// Signed 8 bit integer.
/// </summary>
[CLSASafe(false)]
Int8
}
我現在希望能夠創建一個獨特的類每個枚舉,並且能夠標記它通過查看正在實施的類型作爲CLSSafe。我有以下,這顯然是不正確的,但說明了我的本意:
[CLSASafe((Boolean)typeof(BaseTypes.Object).GetCustomAttributes(typeof(BaseTypes.Object), false))]
sealed public class BaseObject : Field
{
public Object Value;
}
有(從手動標記的簽名分開)這樣做的呢?
哇,非常感謝!你清楚地知道你的屬性! – IamIC