/// <summary> /// Converts a content type to a jsonPayload object /// </summary> /// <param name="contentType"></param> /// <param name="isDeleted">if the item was deleted</param> /// <returns></returns> private static JsonPayload FromContentType(IContentTypeBase contentType, bool isDeleted = false) { var payload = new JsonPayload { Alias = contentType.Alias, Id = contentType.Id, PropertyTypeIds = contentType.PropertyTypes.Select(x => x.Id).ToArray(), //either IContentType or IMediaType or IMemberType Type = (contentType is IContentType) ? typeof(IContentType).Name : (contentType is IMediaType) ? typeof(IMediaType).Name : typeof(IMemberType).Name, DescendantPayloads = contentType.Descendants().Select(x => FromContentType(x)).ToArray(), WasDeleted = isDeleted }; //here we need to check if the alias of the content type changed or if one of the properties was removed. var dirty = contentType as IRememberBeingDirty; if (dirty != null) { payload.PropertyRemoved = dirty.WasPropertyDirty("HasPropertyTypeBeenRemoved"); payload.AliasChanged = dirty.WasPropertyDirty("Alias"); payload.IsNew = dirty.WasPropertyDirty("HasIdentity"); } return(payload); }
/// <summary> /// Get all descendant and self content types /// </summary> /// <param name="contentType"></param> /// <returns></returns> public static IEnumerable <IContentTypeBase> DescendantsAndSelf(this IContentTypeBase contentType) { var descendantsAndSelf = new[] { contentType }.Concat(contentType.Descendants()); return(descendantsAndSelf); }