2

定义如下(在 C# 中)的 AmbientClassAttribute 的用途是什么:

using System;

namespace Metamodel
{
    [AttributeUsage(AttributeTargets.Class, Inherited = true)]
    public sealed class AmbientClassAttribute : System.Attribute
    {
    }
}
4

1 回答 1

2

AmbientClassAttribute顾名思义,就是一个属性类,这意味着它被用作类定义中的一个属性,如下所示:

[AmbientClass]
public class MyClass { }

所有这一切都是添加元数据——它将类标记为 AmbientClass——不管这意味着什么。但是标记自身的行为——添加属性——背后没有任何逻辑,这就是类没有任何成员的原因。它什么也没。它只是将该类标记为环境类。

那有什么呢?它允许其他代码片段,我的类的代码 - 在本例中为 XAML 处理器 - 了解此元数据并相应地处理:“XAML 处理器 [使用它] 确定成员的类型所有者”。

于 2012-08-08T07:33:54.243 回答