private Type type = null;
protected void Page_Load(object sender, EventArgs e)
{
type = typeof(InstanceClass);
}
protected string getObjectProperty(string str)
{
string retValue = "";
try
{
object o = Activator.CreateInstance(type, new object[] { this.txtPropertyValue.Text.Trim()});
PropertyInfo pi = type.GetProperty("ReturnValue", typeof(string));
retValue = pi.GetValue(o, null).ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return retValue;
}
protected string getOjbectMethod(string str)
{
object retValue = null;
try
{
object o = Activator.CreateInstance(type);
MethodInfo mi = type.GetMethod("getFunction", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string)},null);
retValue = mi.Invoke(o, new object[] { str });
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return retValue.ToString();
}
protected void btnGetProperty_Click(object sender, EventArgs e)
{
this.lblPropertyResult.Text = this.getObjectProperty(this.txtPropertyValue.Text.Trim());
}
protected void btnInvoke_Click(object sender, EventArgs e)
{
this.lblInvokeResult.Text = this.getOjbectMethod(this.txtParameter.Text.Trim());
}
}