[IronPython] Using CLR bound COM interfaces
Alex Willmer
alex at moreati.org.uk
Mon Feb 26 02:35:35 CET 2007
Hello,
I've been attempting with IronPython, to access the CLR binding to
ArcObjects[1], a COM based Geographic Information System (GIS) library.
I come at this from a CPython background, so my knowledge of COM & .NET
are lacking.
I'm trying to understand how interfaces (IFoobar) are dealt with in
IronPython. A C# example I'm attempting to transcribe contains the
following lines:
if (!((objectWorkspace is IWorkspace) ||
(objectWorkspace is IFeatureDataset)))
{
throw(new Exception(....));
}
My assumption was that isinstance() would replace 'is', but the
following would indicate otherwise. From the .NET 2.0 docs[2] the
System.Uri class inherits from ISerializable
>>> import System
>>> import System.Runtime.Serialization
>>> x = System.Uri('http://example.net')
>>> isinstance(x, System.Uri)
True
>>> isinstance(x, System.Runtime.Serialization.ISerializable)
False
How should I test a particular object implements an interface?
My second query is based on the following C#:
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit) geometryDef;
// Assign Geometry Definition
geometryDefEdit.GeometryType_2 = geometryType;
geometryDefEdit.GridCount_2 = 1;
geometryDefEdit.set_GridSize(0, 0.5);
geometryDefEdit.AvgNumPoints_2 = 2;
geometryDefEdit.HasM_2 = false;
geometryDefEdit.HasZ_2 = true;
I understand that to transcribe this is I should forget the
assignment/cast and replace geometryDefEdit.Method(args) with
IGeometryDefEdit.MethodName(geometryDef, args). Is this correct?
Many thanks.
Alex Willmer
[1] http://edndoc.esri.com/arcobjects/9.1/
[2] http://msdn2.microsoft.com/en-us/library/system.uri.aspx
More information about the Ironpython-users
mailing list