18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

.NET APPLICATION PROGRAMMING INTERFACE<br />

• Include HRESULTs in user-defined exceptions.<br />

• Supply GUIDs for types that require them.<br />

• Expect inheritance differences.<br />

For more information, review ‘Interoperating with Unmanaged Code’ in the<br />

MSDN help collection.<br />

Performance considerations<br />

COM Interop clearly adds a new layer of overhead to applications, but the overall<br />

cost of interoperating between COM and .NET is small and often unnoticeable.<br />

However, the cost of creating wrappers and having them marshall between<br />

environments does add up; if you suspect COM Interop is the bottleneck in your<br />

application’s performance, try creating a COM worker class that wraps all the<br />

chatty COM calls into one function that managed code can invoke. This improves<br />

performance by limiting the marshalling between the two environments.<br />

COM to .NET type conversion<br />

Generally speaking, the type library importer imports types with the same name<br />

they originally had in COM. All imported types are additionally added to a<br />

namespace that has the following naming convention: ESRI.<strong>ArcGIS</strong> plus the<br />

name of the library. For example, the namespace for the Geometry library is<br />

ESRI.<strong>ArcGIS</strong>.Geometry. All types are identified by their complete namespace and<br />

type name.<br />

Classes, interfaces, and members<br />

All COM coclasses are converted to managed classes; the managed classes have<br />

the same name as the original with ‘Class’ appended. For example, the Point<br />

coclass is PointClass.<br />

All classes also have an interface with the same name as the coclass that corresponds<br />

to the default interface for the coclass. For example, the PointClass has a<br />

Point interface. The type library importer adds this interface so clients can register<br />

event sinks.<br />

The .NET classes also have class members that .NET supports, but COM does<br />

not. Each member of each interface the class implements is added as a class<br />

member. Any property or method a class implements can be accessed directly<br />

from the class rather than having to cast to a specific interface. Since interface<br />

member names are not unique, name conflicts are resolved by adding the interface<br />

name and an underscore as a prefix to the name of each conflicting member.<br />

When member names conflict, the first interface listed with the coclass remains<br />

unchanged.<br />

Properties in C# that have by-reference or multiple parameters are not supported<br />

with the regular property syntax. In these cases, it is necessary to use the accessor<br />

methods instead. The following code excerpt shows an example.<br />

ILayer layer = mapControl.get_Layer(0);<br />

MessageBox.Show(layer.Name);<br />

Chapter 4 • <strong>Developer</strong> environments • 147

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!