Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Last time I tried to do that I had to use a custom converter and invent my own parser for dictionary values. I don't remember which research got me there, but here is the registration and the corresponding converter class.</p> <pre><code>&lt;type type="IRequestPolicy" mapTo="RequestPolicyCatalog, Assembly"&gt; &lt;constructor&gt; &lt;param name="dictionary" type="System.Collections.Generic.KeyValuePair`2[System.Int32,System.String][], mscorlib"&gt; &lt;array&gt; &lt;value value="1, 'unauthorized'" typeConverter="Assembly.IntStringKeyValueConverter, fore.Core"/&gt; &lt;value value="2, 'activation'" typeConverter="Assembly.IntStringKeyValueConverter, Quofore.Core"/&gt; &lt;value value="3, 'routing'" typeConverter="Assembly.IntStringKeyValueConverter, Quofore.Core"/&gt; &lt;/array&gt; &lt;/param&gt; &lt;/constructor&gt; &lt;/type&gt; </code></pre> <pre class="lang-cs prettyprint-override"><code>public class IntStringKeyValueConverter : System.ComponentModel.TypeConverter { public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { return this.ConvertFrom(context, culture, value); } public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string); } public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(KeyValuePair&lt;int, string&gt;); } public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { var comma = ((string)value).IndexOf(','); if(comma &lt; 0) throw new InvalidOperationException("Invalid string, must contain ',' between values"); var number = int.Parse(((string)value).Substring(0, comma)); var str = ((string)value).Substring(comma).Trim(new[] { ',', '\'', ' ' }); return new KeyValuePair&lt;int, string&gt;(number, str); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload