在这里我有三个参数如何移动methodname.Equals('xx')方法移出一个单独的方法。
public static String APIMethod(string modulename,string methodname,string postContent )
{
string recordId = "1";
string uri = zohocrmurl + modulename + "/"+methodname+"?";
/* Append your parameters here */
postContent = "scope=crmapi";
postContent = postContent + "&authtoken=0ac32dc177c4918eca902fd290a92f4a";//Give your authtoken
//how to move this and create them as seperate methods
**if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
{
postContent = postContent + "&xmlData="+ HttpUtility.UrlEncode("Your CompanyHannahSmithtesting@testing.com");
}
if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
{
postContent = postContent + "&id="+recordId;
}**
string result = AccessCRM(uri, postContent);
return result;
}
答案 0 :(得分:0)
为什么不使用switch (C# Reference)
switch语句是一个选择开关的控制语句 从候选人名单中执行的部分。
答案 1 :(得分:0)
如果xxx
部分不修改name
,并且每次都这样做都不同:
public static string rest(string name, string method,string count)
{
switch(name.Trim().ToLower())
{
case: "insert":
{
xxx
break;
}
case: "delete":
{
xxx
break;
}
case: "update":
{
xxx
break;
}
string result = xxx;
return result;
}