Opened 14 years ago

#690 new enhancement

Use generic collection interfaces for managed collections

Reported by: jng Owned by: gregboone
Priority: major Milestone: 3.6.0
Component: FDO API Version:
Severity: 3 Keywords:
Cc: External ID:

Description

Most (all?) collection classes in the current .net wrapper API inherit from CollectionBase which implements the untyped System.Collections.IList interface.

Using the FDO .net API in a .net Framework >= 3.5 environment with C# 3.0 syntax is cumbersome because of the following issues:

  1. Compiler type inference fails on foreach loops:
FeatureSchemaCollection featureSchemas = ...;
foreach(var schema in featureSchemas)
{
    //schema will be inferred as System.Object instead of OSGeo.FDO.Schema.FeatureSchema
}
  1. LINQ to Objects usage such as the fragment below will fail:
FeatureSchema schema = ...;
var cls = schema.Classes.Where(x => x.Name == "MyFeatureClass").FirstOrDefault();

Currently the Cast() extension method has to be used to make these collections LINQ friendly, resulting in ugly casting of each enumerated object.

FeatureSchema schema = ...;
var cls = schema.Classes.Cast<ClassDefinition>().Where(x => x.Name == "MyFeatureClass").FirstOrDefault();

Having CollectionBase as a generic collection class implementing the generic IList<T> interface will make the managed API more friendly to C# 3.0 syntax.

Change History (0)

Note: See TracTickets for help on using tickets.