public static class Th
{
public static T e<T>(T theObject) where T : class
{
return theObject;
}
}
public static class ObjectExtensions
{
public static bool Is<T>(this T o, Func<T, bool> a) where T : class
{
return a(o);
}
}
//...
//logic in a method somewhere
Func<string, bool> valid = property => _myService.SomeValidationMethod(property);
if (Th.e(_request.Property).Is(valid))
{
//do something
}
这段代码适合生产吗?为什么?
编辑:感谢您的所有评论。我希望您在阅读我将 C# 语法延伸到断点时获得的乐趣,就像阅读您的回复一样。