Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Last active December 16, 2015 13:39
Show Gist options
  • Save leekelleher/5442990 to your computer and use it in GitHub Desktop.
Save leekelleher/5442990 to your computer and use it in GitHub Desktop.
Example of using uQuery.IGetProperty with uTwit property-editor.
var node = uQuery.GetNode(1234);
var twitter = node.GetProperty<Our.Umbraco.Models.uTwit>("twitter");
// use the uTwit model...
// twitter.ConsumerKey
// twitter.ConsumerSecret
// twitter.OAuthToken
// twitter.OAuthTokenSecret
// twitter.ScreenName
using System;
using System.ComponentModel;
using System.IO;
using System.Xml.Serialization;
using umbraco;
namespace Our.Umbraco.Models
{
[SerializableAttribute()]
[DesignerCategoryAttribute("code")]
[XmlTypeAttribute(AnonymousType = true)]
[XmlRootAttribute(Namespace = "", IsNullable = false)]
public class uTwit : uQuery.IGetProperty
{
public string ScreenName { get; set; }
public string OAuthToken { get; set; }
public string OAuthTokenSecret { get; set; }
public string ConsumerKey { get; set; }
public string ConsumerSecret { get; set; }
public void LoadPropertyValue(string value)
{
using (var reader = new StringReader(value))
{
var serializer = new XmlSerializer(typeof(uTwit));
var tmp = (uTwit)serializer.Deserialize(reader);
this.ConsumerKey = tmp.ConsumerKey;
this.ConsumerSecret = tmp.ConsumerSecret;
this.OAuthToken = tmp.OAuthToken;
this.OAuthTokenSecret = tmp.OAuthTokenSecret;
this.ScreenName = tmp.ScreenName;
}
}
}
}
@leekelleher
Copy link
Author

Before anyone asks, I could have used either IPropertyEditorValueConverter or IRazorDataTypeModel to handle this. However I was already making good use of uQuery and wanted to explore how the uQuery.IGetProperty works.

Turns out that this ad-hoc non-binding approach worked out very well. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment