2010-09-24 84 views
0

我有一堆C#函数的字符串,int和布尔参数作为数据输入接口。我希望能够为每种方法创建一个网络表单;每个字符串/整数的文本框和每个布尔的复选框。自动化的WebForm生成

有没有办法让这个过程自动化?

回答

0

你需要使用反射来检索方法的签名,然后创建基于其参数的Web表单

// Create a container (panel for instance) 

var parameters = methodInfo.GetParameters(); 
foreach (var parameter in parameters) 
{ 
    if (parameter.ParameterType == typeof(string)) 
    {//Create a text box and add it to the panel} 
    else if (parameter.ParameterType == typeof(int)) 
    {//Create a numeric box and add it to the panel} 
... 
}