public static void SetPropertyValue <TContentItem>(this TContentItem contentItem, Expression <Func <TContentItem, object> > expression, object value) where TContentItem : ContentItem { MemberExpression memberExpression = null; if (expression.Body is MemberExpression) { memberExpression = (MemberExpression)expression.Body; } else if (expression.Body is UnaryExpression) { memberExpression = ((UnaryExpression)expression.Body).Operand as MemberExpression; } if (memberExpression == null) { throw new Exception("The body of the expression must be either a MemberExpression or a UnaryExpression."); } if (value is LinkItemCollection) { //LinkItemCollection needs to be saved as a json string LinkItemCollection links = value as LinkItemCollection; contentItem.SetDetail(memberExpression.Member.Name, links.ToJSONString(), typeof(string)); } else { contentItem.SetDetail(memberExpression.Member.Name, value, ((PropertyInfo)memberExpression.Member).PropertyType); } }
public string Rebase(string value, string fromAppPath, string toAppPath) { //The value being passed in is the raw JSON value stored for the property //We need to identify all links that need to be rebased LinkItemCollection coll = LinkItemCollection.Empty; if (LinkItemCollection.TryParse(value, out coll)) { foreach (LinkItemBase item in coll) { item.RebaseLinkItem(fromAppPath, toAppPath); } } return(coll.ToJSONString()); }