Tuesday, November 4, 2008

Extending the IGeometryCollection type with methods provided on the HashSet(T) class

Author: Baxevanis, Nikos

Overview

As of Kim Hamilton’s post, http://blogs.msdn.com/bclteam/archive/2006/11/09/introducing-hashset-t-kim-hamilton.aspx “HashSet determines equality according to the EqualityComparer you specify, or the default EqualityComparer for the type (if you didn’t specify)”.

The IGeometryCollection type implements the IComparable(T). Using extension methods we “add” methods from the HashSet(T) class so any type that implements the IGeometryCollection appears to have instance methods such as IntersectWith, UnionWith etc.


The IGeometryCollection type implements the IComparable(T).

A HashSet(T) operation modifies the set it’s called on and doesn’t create a new set. The extension methods provided with this article return an IGeometryCollection object rather than modifying the caller set.


Implementation

“Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.” http://msdn.microsoft.com/en-us/library/bb359438.aspxUsing the extension methods in your code

You have to add a reference to Topology.Geometries.GeometryCollectionExtensions.dll
To use the HashSet(T) operations first bring them into scope with a using Topology.Geometries.GeometryCollectionExtensions directive.


Using the HashSet(T) operations


Available for download here: http://tf-net.googlecode.com/files/GeometryCollectionExtensions-Source.zip

No comments:

Post a Comment