Created
October 18, 2016 11:05
-
-
Save leekelleher/3bab3b17dc9e3115306c9851a84e80f0 to your computer and use it in GitHub Desktop.
A QueryString processor for Ditto
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
using System.Web; | |
using Umbraco.Core; | |
namespace Our.Umbraco.Ditto | |
{ | |
public class QueryStringAttribute : DittoProcessorAttribute | |
{ | |
public QueryStringAttribute(string key) | |
: this() | |
{ | |
Key = key; | |
} | |
public QueryStringAttribute() | |
{ } | |
public string Key { get; set; } | |
public override object ProcessValue() | |
{ | |
var qs = HttpContext.Current?.Request?.QueryString; | |
if (qs == null) | |
return null; | |
var propertyName = this.Context.PropertyDescriptor != null | |
? Context.PropertyDescriptor.Name | |
: string.Empty; | |
var key = Key ?? propertyName; | |
return qs.AllKeys.InvariantContains(key) | |
? qs.Get(key) | |
: null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment