C# 从Func获取布尔值<;T、 布尔>;
我想从以下函数中获取布尔值:C# 从Func获取布尔值<;T、 布尔>;,c#,fluent,C#,Fluent,我想从以下函数中获取布尔值: public IGridWithOptions<T> CursorPointerWhen(Func<T, bool> propertySpecifier) { bool r = ???? return this; } public-IGridWithOptions-CursorPointerWhen(Func-propertysspecifier) { 布尔r=???? 归还这个; } 如何做到这一点?您可以像类中的方法一样
public IGridWithOptions<T> CursorPointerWhen(Func<T, bool> propertySpecifier)
{
bool r = ????
return this;
}
public-IGridWithOptions-CursorPointerWhen(Func-propertysspecifier)
{
布尔r=????
归还这个;
}
如何做到这一点?您可以像类中的
方法一样调用,因为对于示例,您有第一个T
参数:
T argument = /* get a instance of generic T argument */;
bool r = propertySpecifier(argument);
您需要有一个T
值才能调用代理:
public IGridWithOptions<T> CursorPointerWhen(Func<T, bool> propertySpecifier)
{
T input = GetInputFromSomewhere();
bool r = propertySpecifier(input);
// ...
return this;
}
它的“价值”是什么?它只在特定字符串的上下文中才有意义。我们没有太多关于您在这里尝试执行的操作的信息,但是您需要从某处获取t
的实例,或者更改您的方法参数。您不想要方法名称后面的
吗there@Jonesy当前位置问题中没有一个。。。它很可能是泛型类型中的方法。Thx Jon,你说得对。此位置不适合放置T实例。这是一个网格组件,我检查了它的源代码,以查看其他属性是如何以这种方式设置的,我更改了代码。现在我有了T实例,我可以调用它:-)
Func<string, bool> longString = x => x.Length > 100;