开发者

Castle Windsor Configuration Type Converter with Dictionary<string, string> property

I have read the Castle Windsor Documentation for Type Converters and passing dictionaries, however I am getting an error that doesn't seem to be mentioned in the docs.

My configuration:

<parameters>
    <controllerTranslations>
        <list>
            <item>
                <areaName></areaName>
                <routeValue>MyRoute</routeValue>
                <translationTable>
                    <dictionary>
                        <entry key="en">MyRouteEn</entry>
                        <entry key="fr">MyRouteFr</entry>
                    </dictionary>
                </translationTable>
            </item>
            ....
        </list>
    </controllerTranslations>
</parameters>

My TypeConverter:

public override object PerformConversion(IConfigura开发者_StackOverflow中文版tion configuration, Type targetType)
{
    var converter = new Converter(configuration.Children, Context);
    var areaName = converter.Get<string>("areaName");
    var routeValue = converter.Get<string>("routeValue");
    var translationTable = converter.Get<Dictionary<string, string>>("translationTable");
    ...
}

I get the error, "You must provide a key for the dictionary entry" when the converter tries to get the dictionary.

Debugging the DictionaryConverter in Windsor, the actual expected schema is as follows, but this doesn't seem right. My test passes and no exception is thrown from Windsor:

<parameters>
    <controllerTranslations>
        <list>
            <item>
                <areaName></areaName>
                <routeValue>MyRoute</routeValue>
                <translationTable>
                    <dictionary key="en">
                        <entry>MyRouteEn</entry>
                    </dictionary>
                    <dictionary key="fr">
                        <entry>MyRouteFr</entry>
                    </dictionary>
                </translationTable>
            </item>
            ....
        </list>
    </controllerTranslations>
</parameters>

With some further testing I think I have found the correct way to implement this:

<parameters>
    <controllerTranslations>
        <list>
            <item>
                <areaName></areaName>
                <routeValue>MyRoute</routeValue>
                <translationTable type="System.Collections.IDictionary, mscorlib">
                    <entry key="en">MyRouteEn</entry>
                    <entry key="fr">MyRouteFr</entry>
                </translationTable>
            </item>
            ....
        </list>
    </controllerTranslations>
</parameters>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜