Cur*_*ous 1 .net c# extension-methods asp.net-core .net-6.0
我声明了一个扩展方法如下
namespace ExtensionMethods
{
public static class MyExtensions
{
const string Nil = "$$$NIL$$$";
public static bool IsEmptyNullOrNil(this string str)
{
if (string.IsNullOrEmpty(str) || str == Nil)
{
return true;
}
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器类中,我包含了命名空间。但程序无法编译。但我可以将该函数用作普通的静态方法。
任何帮助将不胜感激。
您的扩展方法可以通过以下方式访问
if (!employeeFilter.Name.IsEmptyNullOrNil())
Run Code Online (Sandbox Code Playgroud)
或者
if (!MyExtensions.IsEmptyNullOrNil(employeeFilter.Name))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
193 次 |
| 最近记录: |