List<String> in typeConfig

Oct 12, 2009 at 11:24 AM

I want to register a class which has a property of type "List<String>".

I want to configure this property in "typeConfig" section as follows...

<property name="MyStrings"
                        propertyType="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <array>
                  <value value="1" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                  <value value="2" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                </array>
              </property>

But, I am getting the following exception while trying to resolve the class

The configuration file includes a property or parameter which is configured with an array value but has type List`1 which is not an array type. 

Can anybody, please point me how this can be corrected?

 

Oct 13, 2009 at 4:12 AM

The <array> element is specific only to array types not for lists.  So far, the easiest way I found to do this is to cram the values in the value attribute and making use of a type converter.  For example:

<property name="MyStrings"
          propertyType="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          value="1,2,3" typeConverter="CustomObjects.MyTypeConverter, CustomObjects">

Wherein in MyTypeConverter class, I override the ConvertFrom method and convert the value parameter (containing "1,2,3") to a list of string. 

Here's a related thread - http://unity.codeplex.com/Thread/View.aspx?ThreadId=63225.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com