Last active
December 16, 2015 13:39
-
-
Save leekelleher/5442990 to your computer and use it in GitHub Desktop.
Example of using uQuery.IGetProperty with uTwit property-editor.
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
| 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 |
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; | |
| 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; | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before anyone asks, I could have used either
IPropertyEditorValueConverterorIRazorDataTypeModelto handle this. However I was already making good use ofuQueryand wanted to explore how theuQuery.IGetPropertyworks.Turns out that this ad-hoc non-binding approach worked out very well. :-)