I am trying to make this HandlerEvent to run methods original handler unless there is legacy defined on its SimpleAttribute then instead run legacy method. thanks for your help in advance
public static class Extensions
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method)]
public class SimpleAttribute : Attribute
{
public string Name { get; set; }
public string Legacy { get; set; }
}
}
public static async Task HandleEvent<T>(Func<T, Task> handler)
{
var legacy = handler.Method.GetCustomAttribute<SimpleAttribute>().Legacy;
if(legacy == null)
await handler();
else
{
var type = typeof(T).Assembly.GetTypes().Where(t => t.Namespace == handler.Method.DeclaringType.Namespace);
var methodInfo = type.GetMethod(legacy);
methodInfo.Invoke(o, parameters);
}
}
public class Boo
{
[Simple(Name = "FlagName")]
public async Task Foo_OLD()
{
}
[Simple(Name = "FlagName", Legacy= "Foo_OLD")]
public async Task Foo()
{
}
}
Aucun commentaire:
Enregistrer un commentaire