Skip to content

Instantly share code, notes, and snippets.

@FNGgames
Created February 1, 2018 10:17
Show Gist options
  • Save FNGgames/d386a7ab8fe2b9b748133a3165917037 to your computer and use it in GitHub Desktop.
Save FNGgames/d386a7ab8fe2b9b748133a3165917037 to your computer and use it in GitHub Desktop.
Context helpers
public static class ContextHelpers
{
private static readonly Dictionary<string, IContext> _contextsLookup = new Dictionary<string, IContext>();
public static IContext GetContextByName(this Contexts contexts, string name)
{
if (_contextsLookup.Count == 0) SetContextsDictionary(contexts);
return _contextsLookup[name];
}
private static void SetContextsDictionary(Contexts contexts)
{
foreach (var context in contexts.allContexts)
{
_contextsLookup.Add(context.contextInfo.name, context);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment