Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ErrorHandler
- {
- [HandleMessage(ErrorHandling.ERROR)]
- private static void OnError(string message, object context, params object[] args)
- {
- Exception e;
- args.Extract(out e);
- Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
- }
- }
- public static void RegisterStaticHandlers(Type type)
- {
- foreach (var mInfo in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
- {
- var mAttr = mInfo.GetCustomAttribute<HandleMessageAttribute>();
- if (mAttr != null)
- RegisterInstanceHandler(mAttr.Message, mInfo.CreateDelegate<MessageHandler>());
- }
- }
- public class HandleMessageAttribute : Attribute
- {
- public string Message { get; private set; }
- public HandleMessageAttribute(string message)
- {
- Message = message;
- Messages.RegisterInstanceHandler(message, ... method reference here ...);
- }
- }
- static ErrorHandler()
- {
- Messages.RegisterStaticHandlers(typeof(ErrorHandler));
- }
Add Comment
Please, Sign In to add comment