0
我们可以设置自定义以下列方式中引用的DLL的属性类型:设置在枚举值自定义属性中引用的DLL
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class AttributeForExternType : Attribute
{
public ExternTypeAttribute(Type type)
{
ExternType = type;
}
public Type ExternType { get; }
}
// set in assembly info:
[assembly: ExternTypeAttribute(typeof(Extern.Type))]
和自定义属性在我们的项目上枚举和字段设置:
[AttributeUsage(AttributeTargets.Enum)]
public sealed class InternEnumAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class InternFieldAttribute: Attribute { }
enum MyEnum
{
FieldA,
[InternFieldAttribute]
FieldB
}
问题:它能够在引用的枚举值上定义和使用自定义属性吗?
*我们可以设置类型的自定义属性*你确定吗? – xanatos
@xanatos是的,我敢肯定... –
通过引用您的意思是其他第三方DLL? –