public static ContentElement Weld <T>(this ContentElement content) where T : ContentElement, new() { return(content.Weld <T>(typeof(T).Name)); }
public static void Weld(this ContentElement content, ContentElement property) { content.Weld(property.GetType().Name, property); }
public static void Update(this ContentElement contentElement) { contentElement.Data.Merge(JObject.FromObject(contentElement), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union }); }
public static T Get <T>(this ContentElement content) where T : ContentElement { return(content == null ? default(T) : content.Get <T>(typeof(T).Name)); }
/// <summary> /// Updates the content element with the specified name. /// </summary> /// <typeparam name="name">The name of the element to update.</typeparam> /// <typeparam name="element">The content element instance to update.</typeparam> /// <returns>The current <see cref="ContentItem"/> instance.</returns> public static ContentElement Apply(this ContentElement contentElement, string name, ContentElement element) { var elementData = contentElement.Data[name] as JObject; if (elementData != null) { elementData.Merge(JObject.FromObject(element), JsonMergeSettings); } else { contentElement.Data[name] = JObject.FromObject(element, ContentBuilderSettings.IgnoreDefaultValuesSerializer); } return(contentElement); }
/// <summary> /// Adds a content element by name. /// </summary> /// <typeparam name="name">The name of the content element.</typeparam> /// <typeparam name="element">The element to add to the <see cref="ContentItem"/>.</typeparam> /// <returns>The current <see cref="ContentItem"/> instance.</returns> public static ContentElement Weld(this ContentElement contentElement, string name, ContentElement element) { JToken result; if (!contentElement.Data.TryGetValue(name, out result)) { element.Data = JObject.FromObject(element, ContentBuilderSettings.IgnoreDefaultValuesSerializer); element.ContentItem = contentElement.ContentItem; contentElement.Data[name] = element.Data; } return(contentElement); }
/// <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)); }
/// <summary> /// Updates the content element with the specified name. /// </summary> /// <typeparam name="name">The name of the element to update.</typeparam> /// <typeparam name="element">The content element instance to update.</typeparam> /// <returns>The current <see cref="ContentItem"/> instance.</returns> public static ContentElement Apply(this ContentElement contentElement, string name, ContentElement element) { var elementData = contentElement.Data[name] as JObject; if (elementData != null) { elementData.Merge(JObject.FromObject(element), JsonMergeSettings); } else { contentElement.Data[name] = JObject.FromObject(element); } return(contentElement); }
/// <summary> /// Adds a content element by name. /// </summary> /// <typeparam name="name">The name of the content element.</typeparam> /// <typeparam name="element">The element to add to the <see cref="ContentItem"/>.</typeparam> /// <returns>The current <see cref="ContentItem"/> instance.</returns> public static ContentElement Weld(this ContentElement contentElement, string name, ContentElement element) { JToken result; if (!contentElement.Data.TryGetValue(name, out result)) { element.Data = JObject.FromObject(element); element.ContentItem = contentElement.ContentItem; contentElement.Data[name] = element.Data; } return(contentElement); }