Skip to content

Instantly share code, notes, and snippets.

@modulexcite
Forked from rushfrisby/strategy_pattern.cs
Last active August 29, 2015 14:23
Show Gist options
  • Save modulexcite/10984dcca6b7df729096 to your computer and use it in GitHub Desktop.
Save modulexcite/10984dcca6b7df729096 to your computer and use it in GitHub Desktop.
//do this once and cache it
var ruleEngineTypes = new Dictionary<LanguageTypes, Type>();
ruleEngineTypes.Add(LanguageTypes.CSharp, typeof(CSharpRuleEngine));
ruleEngineTypes.Add(LanguageTypes.Python, typeof(PythonRuleEngine));
ruleEngineTypes.Add(LanguageTypes.JavaScript, typeof(JavaScriptRuleEngine));
//switch turns into this...
var ruleEngineType = ruleEngineTypes[policy.LanguageType];
var engine = (IRuleEngine)Activator.CreateInstance(ruleEngineType);
engine.Execute(plan);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment