假设我们有这样的属性:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class LogScopeAttribute : Attribute
{
public string Level { get; private set; }
public LogScopeAttribute(string level)
{
Level = level;
}
}
在这样的上下文中使用:
public class Cat
{
[Log.Scope("Important")]
public void Walk()
{
}
[Log.Scope("Trivial")]
public void Sit()
{
}
}
如何Level
在我的Before
和After
方法中使用该属性?似乎您只能使用流利的界面,但因此我无法引用该LogScope
属性。
public class LoggingAmender : Amendment<object, object>
{
public LoggingAmender()
{
Methods.Where( m => [...] )
.Before(LogScope.LogMethodBefore); // how can I refer to 'Level' of LogScope here?
}
}