Skip to content

Instantly share code, notes, and snippets.

@thunklife
Created April 25, 2012 18:58
Show Gist options
  • Select an option

  • Save thunklife/2492275 to your computer and use it in GitHub Desktop.

Select an option

Save thunklife/2492275 to your computer and use it in GitHub Desktop.
Display Mode Provider DSL For Fun
public class DisplayModeExpression
{
readonly Func<HttpContextBase, bool> _condition;
public DisplayModeExpression(Func<HttpContextBase, bool> condition)
{
_condition = condition;
}
public void UseDisplayMode(string displayModeSuffix)
{
if(string.IsNullOrEmpty(displayModeSuffix) || string.IsNullOrWhiteSpace(displayModeSuffix))
throw new ArgumentException("The Display Mode Suffix cannot be null, empty or whitespace");
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode(displayModeSuffix) {ContextCondition = _condition});
}
}
//Other Global stuff
protected void Application_Start()
{
//Removed other stuff for brevity
When(ctx => ctx.GetOverriddenUserAgent().Contains("Windows Phone OS"))
.UseDisplayMode("WP7");
}
private static DisplayModeExpression When(Func<HttpContextBase, bool> condition)
{
return new DisplayModeExpression(condition);
}
//Closing braces and the like
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment