我有一个具有 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/