/// <summary> /// Gets a content element by its name or create a new one. /// </summary> /// <typeparam name="TElement">The expected type of the content element.</typeparam> /// <typeparam name="name">The name of the content element.</typeparam> /// <returns>The content element instance or a new one if it doesn't exist.</returns> public static TElement GetOrCreate <TElement>(this ContentElement contentElement, string name) where TElement : ContentElement, new() { var existing = contentElement.Get <TElement>(name); if (existing == null) { existing = new TElement(); existing.ContentItem = contentElement.ContentItem; contentElement.Data[name] = existing.Data; return(existing); } return(existing); }
public static T Get <T>(this ContentElement content) where T : IContent { return(content == null ? default(T) : content.Get <T>(typeof(T).Name)); }
/// <summary> /// Gets a content element by its name. /// </summary> /// <typeparam name="TElement">The expected type of the content paelementrt.</typeparam> /// <typeparam name="name">The name of the content element.</typeparam> /// <returns>The content element instance or <code>null</code> if it doesn't exist.</returns> public static TElement Get <TElement>(this ContentElement contentElement, string name) where TElement : ContentElement { return((TElement)contentElement.Get(typeof(TElement), name)); }