/// <summary> /// Modifies a new or existing content part by name. /// </summary> /// <typeparam name="name">The name of the content part to update.</typeparam> /// <typeparam name="action">An action to apply on the content part.</typeparam> /// <returns>The current <see cref="ContentPart"/> instance.</returns> public static ContentItem Alter <TPart>(this ContentItem contentItem, Action <TPart> action) where TPart : ContentPart, new() { var part = contentItem.GetOrCreate <TPart>(); action(part); contentItem.Apply(part); return(contentItem); }
/// <summary> /// Modifies a new or existing content part by name. /// </summary> /// <typeparam name="name">The name of the content part to update.</typeparam> /// <typeparam name="action">An action to apply on the content part.</typeparam> /// <returns>The current <see cref="ContentPart"/> instance.</returns> public static async Task <ContentItem> AlterAsync <TPart>(this ContentItem contentItem, Func <TPart, Task> action) where TPart : ContentPart, new() { var part = contentItem.GetOrCreate <TPart>(); await action(part); contentItem.Apply(part); return(contentItem); }
/// <summary> /// Updates the content part with the specified type. /// </summary> /// <typeparam name="TPart">The type of the part to update.</typeparam> /// <returns>The current <see cref="ContentItem"/> instance.</returns> public static ContentItem Apply <TPart>(this ContentItem contentItem, TPart part) where TPart : ContentPart { contentItem.Apply(typeof(TPart).Name, part); return(contentItem); }