The Bitter Coder Tutorials, Binsor Style III: Dictonaries
public class AliasService
{
private Dictionary<string, string> _aliases;
public Dictionary<string, string> Aliases
{
get { return _aliases; }
set { _aliases = value; }
}
public string Evaluate(string term)
{
if (_aliases == null) return term;
while (_aliases.ContainsKey(term))
{
term = _aliases[term];
}
return term;
}
}
static void Main(string[] args)
{
AliasService aliasService = container.Resolve<AliasService>();
string sentence = "a dog ate my homework";
foreach (string word in sentence.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
Console.Write("{0} ", aliasService.Evaluate(word));
}
}
import System
import System.Reflection
import System.Collections.Generic
import BitterCoder.Tutorials.Binsor.Core
aliases=Dictionary [of string, string]()
aliases['dog']="duck"
aliases['ate']="broke"
aliases['homework']="code"
component "aliases.service", AliasService:
Aliases=aliases