|
Use reflection, please refer to:
string sClass = CCConvert.GetRequsetQueryString ("ClassName");
string sMethodName = "GetReports";
// Get class
Type oType = System.Type.GetType ("CallCenter.Report.Class." + SClass);
if (oType == null)
{
Response.Write ("Class:" + sClass + "Does not exist!");
return;
}
// Implementation
object oInst = Activator.CreateInstance (oType);
if (oInst == null)
{
Response.Write ("Class:" + sClass + "Does not exist!");
return;
}
// Get method
MethodInfo oMethod = oType.GetMethod (sMethodName);
if (oMethod == null)
{
Response.Write ("Method:" + sMethodName + "Does not exist!");
return;
}
int iParamsCount = oMethod.GetParameters (). Length;
string sParams = CCConvert.GetRequsetQueryString ("Params");
string [] ary = sParams.Split (',');
if (ary.Length! = iParamsCount)
{
Response.Write (String.Format ("The number of passed parameters {0} is not equal to the actual number of parameters {1} of the method {2}, please check", ary.Length.ToString (), oMethod.Name , iParamsCount.ToString ()));
return;
}
// Get attributes
PropertyInfo Pro = oType.GetProperty ("Title");
Ranch
this.sTitle = Pro.GetValue (oInst, null) .ToString ();
Ranch
FieldInfo fldFileName = oType.GetField ("sExcelFileName");
Ranch
Ranch
string sHTML = oMethod.Invoke (oInst, BindingFlags.Public, Type.DefaultBinder, ary, null) .ToString ();
string sFileName = fldFileName.GetValue (oInst) .ToString ();
//Response.Write(sFileName); |
|