Click here to Skip to main content
15,887,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a singleton localization class with indexer. You can access it like this:
C#
Localize.Current[String key]
I also have a custom Binding class that transforms string into a call to this indexer:
C#
{Translate MyKey}
This will set Mode (OneWay) on my the binding, source to Localize.Current (singleton) and also path to:
C#
[^__b__^$key$]
Where $key$ is evaluated to MyKey. Then it is localized and replaced by a localized value. Now I want to parameterize this binding with additional parameters. So I did this:
C#
Localize.Current[String key, params String[] parameters]
{Translate MyKey, MyParameter1, MyParameter2}
I don't know how to set path in the binding to this. I need a path that contains reference to array something like:
C#
new PropertyPath("[key, $array_placeholder$], values)
Can't finding anything anywhere. Neither in documentation, nor Google. Anyone has experience how to achieve this? What to put instead of $array_placeholder$?

What I have tried:

I've tried:
C#
new PropertyPath("[key, (0)]", values) // where values is String[] from Translate
This doesn't trigger the indexer. It triggers Localize.Current[String key, String parameter] indexer, if I add one, but not an arbitrary amount of arguments.
Posted
Updated 15-Feb-21 5:33am

1 solution

I haven't tried it, but I suspect the binding is ignoring the params modifier on your indexer parameter. It wants a one-to-one mapping from the PathParameters to the indexer parameters - ie: a single string, and a single string array.

Try:
C#
string[] parameters = new string[values.Length - 1];
if (parameters.Length != 0) Array.Copy(values, 1, parameters, 0, parameters.Length);
binding.Path = new PropertyPath("[key, parameters]", values[0], parameters);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900