0
Это мой код атрибута класса, который расширяет IMethodDecorator интерфейспараметров передают конструктору в методе Decorator Fody
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Field)]
public class LogAttribute : Attribute, IMethodDecorator
{
ILogger log = Logger.Factory.GetLogger<Logger>();
String methodName;
public LogAttribute() {
}
public void Init(object instance, MethodBase method, object[] args)
{
methodName = method.Name;
}
public void OnEntry()
{
Console.WriteLine(methodName);
log.Debug(methodName);
}
public void OnExit()
{
Console.WriteLine("Exiting Method");
}
public void OnException(Exception exception)
{
Console.WriteLine("Exception was thrown");
}
}
Я хочу, чтобы иметь возможность использовать это как
[log("some logmessage")]
void method()
{
// some code
}
Любые идеи? Я использую пакет Method Decorator Fody.
атрибутов в .NET позволяет параметр застройщик; вы пробовали 'public LogAttribute (string logMessage) {}'? – jlvaquero
MethodDecorator Fody не работает с параметризованным конструктором. –