How to simplify these statement

Jan 11, 2009 at 9:16 AM
Edited Jan 11, 2009 at 9:17 AM
switch (title)
            {
               .....
                case "规格设置":
                    if (action == LoadAction.GetList) s = GetJson<t_gg>("", obj[0] as string, obj[1] as string, obj[2] as string);
                    else if (action == LoadAction.GetOneRecord) s = GetJsonOne<t_gg>(obj[0] as string);
                    else if (action == LoadAction.SaveOneRecord) s = SaveJsonOne<t_gg>(obj[0] as string, (System.Web.HttpRequest)obj[1]);
                    break;
                case "商品类设置":
                    if (action == LoadAction.GetList) s = GetJson<t_spl>("", obj[0] as string, obj[1] as string, obj[2] as string);
                    else if (action == LoadAction.GetOneRecord) s = GetJsonOne<t_spl>(obj[0] as string);
                    else if (action == LoadAction.SaveOneRecord) s = SaveJsonOne<t_spl>(obj[0] as string, (System.Web.HttpRequest)obj[1]);
                    break;
                case "商品名称与数字编码设置":
                    if (action == LoadAction.GetList) s = GetJson<t_spmc>("", obj[0] as string, obj[1] as string, obj[2] as string);
                    else if (action == LoadAction.GetOneRecord) s = GetJsonOne<t_spmc>(obj[0] as string);
                    else if (action == LoadAction.SaveOneRecord) s = SaveJsonOne<t_spmc>(obj[0] as string, (System.Web.HttpRequest)obj[1]);
                    break;
               .....
            }

private static string GetJson<T>(string Jorderby, string type,string start,string limit) where T : class, IDbObject


private static string SaveJsonOne<T>(string key,System.Web.HttpRequest Request) where T : class, IDbObject

 private static string GetJsonOne<T>(string key) where T : class, IDbObject


I don't know how to simplify these statement.... beacause 一个string对应着一个class,
不知道怎么把string 和 class存进一个hasetable.所以很苦恼。


就算存进去了,调用进入这个<>的时候也会报错,于是只能这么弄。好笨。

不知道我是否表达清楚了。

就是说有没有什么办法可以这样:

var T = GetClassType(string s)

然后

var xxx=GetJson<T>(....bla..bla..bla

总而言之,就是说这个var T = GetClassType(string s)我总是搞不定。
Coordinator
Jan 11, 2009 at 10:29 AM
            switch (title)
            {
               .....
                case "规格设置":
                    Process<t_gg>(obj);
                    break;
                case "商品类设置":
                    Process<t_spl>(obj);
                    break;
                case "商品名称与数字编码设置":
                    Process<t_spmc>(obj);
                    break;
               .....
            }

private void Process<T>(object[] obj)  where T : class, IDbObject
{
    if (action == LoadAction.GetList) s = GetJson<T>("", obj[0] as string, obj[1] as string, obj[2] as string);
    else if (action == LoadAction.GetOneRecord) s = GetJsonOne<T>(obj[0] as string);
    else if (action == LoadAction.SaveOneRecord) s = SaveJsonOne<T>(obj[0] as string, (System.Web.HttpRequest)obj[1]);
}