The curiosity of the let_ property method

梦想与她 提交于 2019-12-04 22:54:26
Ruben Bartelink

It's a COM thing which is surfaced in VB. Set assigns a reference to replace a property's referred-to item, whereas Let is expected to copy the content of the operand into the existing property. (See also Property Get).

IIRC this is not a core COM thing, more something that's used where a language doesnt have sufficient expressive power to deal with value vs reference issues to a sufficiently precise degree - I believe it may only apply when you're using IDispatch (where you''re addressing by property id rather than method) rather than a custom interface (where you always have to resolve to a method and call that). I'm pretty sure VB.NET (or other .NET languages) doesnt surface such things and hence they're a rare thing.

Essential COM by Box doesnt mention it (only propget and propput for get and set). COM IDL & Interface Design by Dr Al Major mentions it on P106 ans says:

dispinterface DMyInterface { methods:
...
[id(3), propputref] void lMyProp([in] IDispatch *pDisp);
}

The propputref attribute is an odd little thing that has its origins in the idiosynracies of Visual Basic syntax. Consider the following:

Dim val as DMyOtherInterface
Dim var as DMyInterface

Set var.lMyProp = val
var.lMyProp = val

The two assignments are both permissible but mean completely different things. The use of the Set keyword in the first assginment indicates that lMyProp is being assigned an interface [...]. The second assignment is a simpe one, where the value of the val object, which is the value of the default member of the DMyOtherInterface interface (the default member is the member tagged by the DISPID_VALUE ID, as will be explained shortly), is being assigned to the lMyProp property of the DMyInterface interface.

The first assignment is carried out using the propputref method associated with the lMyProp property, while the second assignment uses the propput method. In order for this to work, both the propputref and propput methods must be defined. If you're confused by this way of doing things, you're not alone. While VB has many good features that have fundamentally changed the nature of programming, the definition of the language was predominantly market-driven rather than being designed, and sometimes it shows.

Amusingly I havent ever used the Major book since reading it in early 2000 before the COM and .COM bust (Its a good book for its purpose though). Thanks for the trip down memory lane - I love the way people tell us that programming keeps getting harder!

Dont have the Lidin book with me to see if it mentions .other but I'm sure you do (BTW thanks a lot for Mono.Cecil)

Visual Studio automation is based upon COM. The property in question has probably been generated via a tool to support COM Interop (tlbimp potential). I doubt anyone coded this in an actual .Net based language.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!