using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
namespace ConsoleMenuTesting{
class Option
{
public string name;
string subMenu;
MethodInfo methodInfo;
object methodTarget;
object[] args;
//
public static MenuSystem console;
public Option(string name, string subMenu, MethodInfo method, object target)
{
this.name = name;
this.subMenu = subMenu;
this.methodInfo = method;
this.methodTarget = target;
}
protected Option(string name, string subMenu, MethodInfo method, object target, object[] args)
:this(name, subMenu, method, target)
{
this.args = args;
}
public string SubMenu { get { return subMenu; } }
[DebuggerNonUserCode]
void Invoke()
{
this.methodInfo.Invoke(this.methodTarget, args);
}
public void EventHandlerInvoke(object sender, EventArgs e)
{
Invoke();
}
public void EventHandlerInvokeOnBackground(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(InvokeWC);
}
private void InvokeWC(object unusedParameter)
{
#if !NETCF
Invoke();
#else
try {
Invoke();
} catch (Exception ex) {
console.WriteLine("Swallowed Exception: " + ex);
console.ReadLine("Continuing after: " + ToStringFirstLine(ex));
}
#endif
}
static string ToStringFirstLine(object @this)
{
using (System.IO.StringReader rdr = new System.IO.StringReader(@this.ToString())) {
return rdr.ReadLine();
}
}
}
}
|