Example #1
0
 public static ContentElement Weld <T>(this ContentElement content) where T : ContentElement, new()
 {
     return(content.Weld <T>(typeof(T).Name));
 }
Example #2
0
 public static void Weld(this ContentElement content, ContentElement property)
 {
     content.Weld(property.GetType().Name, property);
 }
Example #3
0
 public static void Update(this ContentElement contentElement)
 {
     contentElement.Data.Merge(JObject.FromObject(contentElement), new JsonMergeSettings {
         MergeArrayHandling = MergeArrayHandling.Union
     });
 }
Example #4
0
 public static T Get <T>(this ContentElement content) where T : ContentElement
 {
     return(content == null ? default(T) : content.Get <T>(typeof(T).Name));
 }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <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);
        }
Example #7
0
 /// <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));
 }
Example #8
0
        /// <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);
        }
Example #9
0
        /// <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);
        }