Initial situation:
I am working with a proprietary framework ( ESRI ArcGIS Engine ), which I want to extend with some new features. I decided to use extension methods in C # for this.
The following are parts of the infrastructure API that are relevant to this issue:
+------------------------+ IGeometry
| IFeature <interface> | <interface>
+------------------------+ ^
| +Shape: IGeometry | |
+------------------------+ +---------+---------+
| |
IPoint IPolygon
<interface> <interface>
What I want to do:
I want to write an extension method for IFeaturethat will allow the following:
IFeature featureWithPointShape = ...,
featureWithPolygonShape = ...;
featureWithPointShape.DoSomethingWithPointFeature();
featureWithPolygonShape.DoSomethingWithPointFeature();
, , (IPoint IPolygon) (IFeature), . IFeature, IFeature IGeometry, .
:
IFeature Shape (. ), ?
public static void DoSomethingWithPointFeature(this IFeature feature)
{
if (!(feature.Shape is IPoint))
{
throw new NotSupportedException("Method accepts only point features!");
}
...
}
( - - IFeature, FeatureWithShape<IPoint>, -, - IFeature -?)