[IronPython] Revisiting interfaces and COM
Alex Willmer
alex at moreati.org.uk
Tue Mar 17 15:44:36 CET 2009
2009/3/16 Dino Viehland <dinov at microsoft.com>:
> The resolution of that bug was that we now expose explicitly
> implemented interfaces automatically if there are no naming
> conflicts. But with COM it's usually a different story - the
> members should always just be there.
> Do the interop libraries use explicit interface implementation
> (if they did the method names would show up as something
> like Namespace.IFoo.Bar in ildasm)?
I'm afraid I can't answer that, my understanding of .NET interfaces is
shaky, to say the least. Here, thanks to your ildasm tip, is what I
know.
1. The interop library shows LayerFileClass to be defined as:
.class public auto ansi import ESRI.ArcGIS.Carto.LayerFileClass
extends [mscorlib]System.Object
implements ESRI.ArcGIS.Carto.LayerFile,
ESRI.ArcGIS.Carto.ILayerFile,
[ESRI.ArcGIS.System]ESRI.ArcGIS.esriSystem.IDocumentVersion
{
.custom instance void
[mscorlib]System.Runtime.InteropServices.ClassInterfaceAttribute::.ctor(int16)
= ( 01 00 00 00 00 00 )
.custom instance void
[mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string)
= ( 01 00 24 44 44 43 32 33 34 36 44 2D 36 32 44 30 //
..$DDC2346D-62D0
2D 34 45 41 33 2D 41 42 34 32 2D 36 34 41
39 35 // -4EA3-AB42-64A95
35 37 31 35 37 43 36 00 00 )
// 57157C6..
.custom instance void
[mscorlib]System.Runtime.InteropServices.TypeLibTypeAttribute::.ctor(int16)
= ( 01 00 02 00 00 00 )
.method public specialname rtspecialname
instance void .ctor() runtime managed internalcall
{
} // end of method LayerFileClass::.ctor
...
.method public hidebysig newslot virtual
instance void Open([in] string marshal( bstr) sFile)
runtime managed internalcall
{
.override ESRI.ArcGIS.Carto.ILayerFile::Open
} // end of method LayerFileClass::Open
2. Introspecting the instance of LayerFileClass suggests all is well,
only once I try to access an attribute directly does an exception
occur:
IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference('ESRI.ArcGIS.System')
>>> clr.AddReference('ESRI.ArcGIS.Carto')
>>> clr.AddReference('ESRI.ArcGIS.Geodatabase')
>>>
>>> from ESRI.ArcGIS import esriSystem
>>> from ESRI.ArcGIS import Carto
>>> from ESRI.ArcGIS import Geodatabase
>>> lf = Carto.LayerFileClass()
>>> lf
<ESRI.ArcGIS.Carto.LayerFileClass object at 0x000000000000002B>
>>> dir(lf)
['Close', 'CreateObjRef', 'DocumentVersion', 'Equals', 'Filename', 'GetHashCode'
, 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'IsLayerFile', '
IsPresent', 'IsReadOnly', 'Layer', 'MemberwiseClone', 'New', 'Open', 'ReferenceE
quals', 'ReplaceContents', 'Save', 'SaveAs', 'Thumbnail', 'ToString', '__class__
', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new_
_', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__']
>>> lf.Open('h:\\test.lyr')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'GenericComObject' object has no attribute 'Open'
>>> Carto.ILayerFile.Open(lf, 'h:\\test.lyr')
>>>
More information about the Ironpython-users
mailing list