views:

1418

answers:

5

I have a class of type ISimpleCache<IBrokeredDataObject> that I want to add as a type alias (then a type) in the App.Config file

the line

<typeAlias alias="ISimpleCacheOfIBrokeredDataObject" type="MyApplication.ISimpleCache<IBrokeredDataObject>, MyApplication" />

is obviously wrong due to the <>, however I'm not convinced escaping them;

<typeAlias alias="ISimpleCacheOfIBrokeredDataObject" type="MyApplication.ISimpleCache&lt;IBrokeredDataObject&gt;, MyApplication" />

is correct either.

I am currently ripping my code apart to use Unity, so am too far from a compilable code base to test this quickly, and was hoping to get some confirmation here.

+3  A: 

Check out this blog post:

In order to write a generic type, use the ` sign followed by the number of generic types that the interface/class receives.

And a comment in the same page said:

In order to use a constant type in the generic you need to use brackets ([[ ]]).

So I guess your configuration file should contain something like this:

<typeAlias alias="ISimpleCacheOfIBrokeredDataObject"
   type="MyApplication.ISimpleCache`1[[MyApplication.IBrokeredDataObject, MyApplication]], MyApplication" />
Hosam Aly
+1  A: 

And this is strongly signed type as generic parameter.

<typeAlias alias="IPublisherOfXElement" type="MyLib.IX.IPublisher`1[[System.Xml.Linq.XElement, System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MyLib.IX" />
Pavel Savara
A: 

Where is this documented? This is a horrible syntax. Looks copy/pasted from the debugger :(

Mark Richman
+1  A: 

And this is how you use a type that receives two generic types:

<section name="doubleFamilyConfig"
         type="ConfigTest.Configuration.FamilySection`2[
               [ConfigTest.Types.Child, ConfigTest],
               [ConfigTest.Types.Parent, ConfigTest]
               ],
               ConfigTest" />

You can use each type on a different line if you wish, so that it is easier to understand. Note that the first bracket must be right after the type ( FamilySection`2**[** ).

Alex Vilela
+3  A: 

answer for how to use generic types in app.config: link

Boris
nice post, thanks
johnc