Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Adds the properties of a page to an object collection
private void AddPageDataToJson(PageData page, ICollection<object> parentNode, LanguageSelector language)
{
var item = new Dictionary<string, object>
{
{"url", page.GetExternalUrl()},
{"pageid", page.ContentLink.ID.ToString(CultureInfo.InvariantCulture)}
};
foreach (var property in page.Property.Where(x => x.IsPropertyData))
{
object value = "";
if (property.Value != null)
{
switch (property.Type)
{
case PropertyDataType.PageReference:
value = ((PageReference)property.Value).GetExternalUrl();
break;
case PropertyDataType.ContentReference:
value = ((ContentReference)property.Value).GetExternalUrl(page.LanguageBranch);
break;
default:
if (property.GetOriginalType() == typeof (PropertyContentArea))
{
value = ParseContentArea(property.Value as ContentArea, language);
}
else
{
value = property.Value.ToString();
}
break;
}
}
item.Add(property.Name, value);
}
parentNode.Add(new { resource = item });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment