I have a model class called UnicodeMap that I use to represent the hexadecimal unicode value and its consonants and values for Amharic characters.
public sealed class UnicodeMap
{
public string Letter;
public string Consonant;
public string Vowel;
}
I have stored the mapping in CSV and read in runtime to populate a dictionary.
Here is the excerpt of the code that reads and populates the dictionary:
private Dictionary<string, UnicodeMap> _unicodeMap;
void ReadMap()
{
var engine = new FileHelperAsyncEngine<UnicodeMap>();
using (engine.BeginReadFile(MapFile))
{
foreach (var record in engine)
{
_unicodeMap.Add(record.Letter, record);
}
}
}
When I try to get a value from the dictionary using TryGetValue, it always returns false:
public void Translate(string text)
{
var words = text.Split(' ', '.');
foreach (var word in words)
{
var chr = Char.Parse(word);
var unicodeStr = @"\u" + ((int) chr).ToString("X4");
UnicodeMap map;
if (_unicodeMap.TryGetValue(unicodeStr, out map)) //returns false
{
_animator.SetTrigger(map.Consonant);
_animator.SetTrigger(map.Vowel);
};
}
}
For example, when the string is "ሀ", the value of the unicodeStr variable is "\u1200". And I have a string with the value "\u1200" as a key in the dictionary. However, TryGetValue cannot seem to find the key in the dictionary.
How can I solve this issue? What is the possible cause?
Edit: Added a gif of the debugger looking at the values of _unicodeMap dictionary