该let_财产法的好奇心 [英] The curiosity of the let_ property method

查看:286
本文介绍了该let_财产法的好奇心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每一个.NET开发人员知道属性的概念。粗略99.99%,它只是一块元数据的两种方法,一个getter粘合在一起,并制定者。

同样的事情一般无二的事件,他们的添加,删除,并调用方法。

在ECMA-335描述了«其他»一种方法语义,这将适用于任何一个属性或一个事件。从概念上讲,一个属性或事件可以具有多个数目的«其他»方法

今天我偶然发现了一个属性与«其他»法的第一天。当然它必须与COM。接口EnvDTE.Property,在EnvDTE组件(用于写入加载项到Visual Studio),包含定义的属性如下:

  .property对象值()
{
  .custom实例无效[mscorlib程序] System.Runtime.InteropServices.DispIdAttribute ::。ctor的(INT32)=(01 00 00 00 00 00 00 00)
  。获得实例对象EnvDTE.Property::get_Value()
  。其他情况下无效EnvDTE.Property::let_Value(object)
  .SET实例无效EnvDTE.Property::set_Value(object)
}
 

使用let_Value被定义为:

 。方法公开hidebysig newslot specialname抽象的虚拟
        例如无效let_Value([IN]的对象元帅(结构)lppvReturn)运行管理internalcall
{
  .custom实例无效[mscorlib程序] System.Runtime.InteropServices.DispIdAttribute ::。ctor的(INT32)=(01 00 00 00 00 00 00 00)
}
 

显然,VBScript和VB版本的VB.NET之前可以定义使用let关键字属性。而让具有相同的签名设置。我感觉到,有一个关系在这里。

但没有人知道如何该属性已经在EnvDTE已写入的语言被宣布?我怎么能创建具有相同模式的组件(不使用ILASM,这将是太容易了)?而且没有任何人有面临着类似的属性?

和有没有人见过其他«其他»物业,说不定比这不同的语义?如果有,是什么,他们用?

解决方案

这是浮现在VB一个COM的事情。 <一href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vastmPropertySet.asp"相对=nofollow>设置分配基准更换物业的提及到的项目,而<一href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vastmPropertyLet.asp"相对=nofollow>让预期操作数的内容复制到现有财产。 (参见<一个href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vastmpropertyget.asp"相对=nofollow>属性获取)。

IIRC这是不是一个核心的COM的东西,更多的东西是用在一个语言可是没有足够的EX pressive权力处理价值VS引用问题到足够precise程度 - 我认为它可能只适用当你使用IDispatch接口(其中特殊照顾解决因物业编号而不是方法),而不是一个自定义的界面(你总是有解决的方法和调用)。我是pretty的肯定VB.NET(或其他.NET语言)犯规面这样的事情,所以他们是一个罕见的事情。

按箱基本COM犯规提到它(仅propget和propput get和set)。 COM IDL和放大器;接口设计博士铝主要提到它在P106答说:

 调度接口DMyInterface {方法:
...
[ID(3),propputref]无效lMyProp([IN]的IDispatch * pDisp);
}
 

     

propputref 属性是一个奇怪的小thign,有它在Visual Basic语法的idiosynracies起源。考虑以下几点:

 暗淡VAL为DMyOtherInterface
昏暗var当成DMyInterface

设置var.lMyProp = VAL
var.lMyProp = VAL
 

     

这两个任务都是允许的,但意思完全不同的事情。使用第一assginment在设置关键字表明lMyProp被分配一个接口[...]。第二个任务是simpe之一,其中的的在 VAL 的对象,这是<$ C $的默认成员的价值C> DMyOtherInterface 界面(默认成员是基于标记为 DISPID_VALUE ID的成员,将简要说明),被分配到 lMyProp DMyInterface 接口的属性。

     

第一分配进行了使用与lMyProp属性相关联的propputref方法,而第二分配使用propput方法。为了使这项工作,无论是propputref的的propput方法必须定义。 如果您通过这样的方式做事糊涂,你并不孤单。虽然VB有很多很好的功能,从根本上改变程序的性质,语言的定义是predominantly以市场为导向,而不是被设计的,有时它显示

有趣的是我还没有用过的专业书,因为COM和.COM萧条(它的一本好书,其目的虽然)之前,在2000年初读它。感谢您的掉电记忆车道之旅 - 我爱的方式的人告诉我们,编程状态越来越难

不要有Lidin本书我看看它提到。其他,但我敢肯定,你做(顺便说一句感谢很多Mono.Cecil能做到)

Every .net developer knows about the concept of properties. A rough 99.99%, it's just a piece of metadata gluing together two methods, a getter, and a setter.

Same thing usually goes for events, with their add, remove, and invoke method.

The ECMA-335 describes a «Other» kind of method semantic, that would apply to either a property or an event. Conceptually, a property or an event could have a multiple number of «other» methods.

Today's the first day I stumbled upon a property with an «other» method. And of course it had to be related to COM. The interface EnvDTE.Property, in the EnvDTE assembly (used to write addins to Visual Studio), contains a property defined as follows:

.property object Value()
{
  .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 00 00 00 00 00 00 ) 
  .get instance object EnvDTE.Property::get_Value()
  .other instance void EnvDTE.Property::let_Value(object)
  .set instance void EnvDTE.Property::set_Value(object)
}

With let_Value being defined as:

.method public hidebysig newslot specialname abstract virtual 
        instance void  let_Value([in] object  marshal( struct) lppvReturn) runtime managed internalcall
{
  .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 00 00 00 00 00 00 ) 
}

Apparently, VBScript and versions of VB before VB.NET can define properties using a Let keyword. And the Let has a same signature as the Set. I sense that there's a relationship here.

But does anyone know how this property have been declared in the language that EnvDTE has been written with? How could I create an assembly with the same pattern (without using ilasm, that would be too easy)? And does anyone have faced a similar property?

And does anyone have seen other «other» properties, with maybe a different semantic than this one? And if yes, what are they used to?

解决方案

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 thign 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)

这篇关于该let_财产法的好奇心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆