.net - Linq 和对象的包装器

标签 .net vb.net linq

我有一个具有 Width 属性的类 MyObj
我需要将该属性从 MyObj 删除到将包装 MyObj 的 MyObjWrapper
我这样使用它:

Dim _MyObjWrapper As MyObjWrapper = New MyObjWrapper(_myObj)
Dim theWidth as Integer = _MyObjWrapper.Width

选择我使用的 MyObj 的特定宽度

Dim q = From mo In myContainer.GetMyObjs() 
        Where mo.Width > 50 
        Select mo.Width Distinct

现在,如果Width不再属于MyObj,我想使用mo.Width代替moWrapper.Width :

Dim q = From mo In myContainer.GetMyObjs() 
        Where New MyObjWrapper(mo).Width > 50 
        Select New MyObjWrapper(mo).Width Distinct

有没有办法使用两次包装器的构造函数MyObjWrapper(mo)?

最佳答案

我的 VS 安装现在表现得很疯狂,所以我无法对此进行测试,但请尝试以下操作:

Dim q = From mo In myContainer.GetMyObjs() 
        Let someObj = New MyObjWrapper(mo)
        Where someObj.Width > 50 
        Select someObj.Width.Distinct

关于.net - Linq 和对象的包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066012/

相关文章:

c# - XAML 分组 ListView : Changing a row background color

c# - LINQ 加入具有 NULL 元素的多个数据集

c# - Lock() { ... } 等待时间

C# 根据日期(月)和组拆分查询结果

c# - 从 C# 访问 Win32/MFC "Stuff"

vb.net - 如何将vb类添加到类库中?

c# - 检索大型记录集时 DataReader 挂起

c# - .net - Array.Sort 和 Array.BinarySearch 的问题 - 文化和全局化

c# - LINQ TO XML,如何用新值替换值 c#

c# - 为什么不能从扩展类型的基类中调用扩展方法?