以下是.NET Framework 3.5中創建的一個類別庫檔案中的方法:
/// <summary>
/// 轉換為string字串型別
/// </summary>
/// <param name="s">獲取需要轉換的值</param>
/// <param name="format">需要格式化的位數</param>
/// <returns>回傳一個新的字串</returns>
public static string ToStr(this object s, string format = "")
{
string result = "";
try
{
if (format == "")
{
result = s.ToString();
}
else
{
result = string.Format("{0:" + format + "}", s);
}
}
catch
{
}
return result;
}
當以上類別庫檔案被匯入到.NET Framework 4.5的web專案的App_Code檔案夾中,在其類別庫檔案中呼叫其方法如下:
public static string GetRequestStr(this object c, string key, bool filterSQL = true)
{
string textValue = HttpContext.Current.Request[key].ToStr(""); //在這里出現問題
if (filterSQL && textValue.Trim() != "")
{
textValue = textValue.filterSQL(); //進行字串的驗證,判斷是否包含特殊字符或關鍵字,如果包含則進行特殊字符處理。
}
return textValue;
}
頁面提示問題如下:
CS0121: The call is ambiguous between the following methods or properties: 'UserUtility.Utility.ToStr(object, string)' and 'UserUtility.Utility.ToStr(object, string)'
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/270130.html
標籤:ASP.NET
