NameTypeConfigurationElementCollection question

Topics: Enterprise Library Core
Mar 20, 2007 at 10:45 PM

I'm trying to compile the Updater Application Block against Entlibv3.
The original version was compiled Entlib v2.

The problem I have is that NameTypeConfigurationElementCollection has changed from

public class NameTypeConfigurationElementCollection<T> : PolymorphicConfigurationElementCollection<T>
where T : NameTypeConfigurationElement, new()


public class NameTypeConfigurationElementCollection<T, TCustomElementData> : PolymorphicConfigurationElementCollection<T>
where T : NameTypeConfigurationElement, new()
where TCustomElementData : T, new()

There's an extra generic parameter added.
When I look at the code I see that this is to handle the fact if the providertype of a value is not found that this type can be used instead (where in Entlibv2 an exception would be thrown).

That is what I read in code, but I don't understand what this actually does.

Could someone shed some light on this, so I can choose how to handle this.
Right now I'm just giving the same type along (since this is a restriction that is enforced)

Best regards,
Mar 20, 2007 at 11:56 PM
Hi Ike -

The second generic parameter represents the runtime configuration type that is used for loosely-typed providers. As an example, in the Logging Application Block if you try to add a new Filter with the config tool you'll see a list of options for the various types of Trace Listeners (category, priority, etc). These show up in the tool since each one has a strongly-typed configuration class and associated designtime node and command. You'll also see a Custom Filter option which creates a node with properties for the runtime LogFilter type and a property bag (name/value pairs) for additional configuration data. These "custom" provider nodes simplify development of custom providers as it eliminates the need to build the configuration and node classes, but come at a cost of not having strongly-typed or validated configuration.

Sticking to the Log Filter example, the declaration for LoggingSettings.Filters is
public NameTypeConfigurationElementCollection<LogFilterData, CustomLogFilterData> LogFilters
        return (NameTypeConfigurationElementCollection<LogFilterData, CustomLogFilterData>)base[logFiltersProperty];
} the second generic parameter refers to the configuration class that stores the type and property bag for "custom" filters.

I'm not familiar with the Updater Application Block code so I don't know if such a configuration class exists or not.