Created
April 25, 2012 18:58
-
-
Save thunklife/2492275 to your computer and use it in GitHub Desktop.
Display Mode Provider DSL For Fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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