Internal class referencing stuff from Umbraco 7.3, which isn't available in Umbraco 7.2. Since only this class is referencing code in Umbraco 7.3, we can make a release that works for both Umbraco 7.2.x and 7.3.x.
        /// <summary>
        /// Parses a control from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="area">The parent area of the control.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridControl Parse(GridArea area, JObject obj)
        {
            // Set basic properties
            GridControl control = new GridControl(obj)
            {
                Area = area
            };

            Howdy.ReplaceEditorObjectFromConfig(control);

            // Parse the editor
            control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x));

            // Parse the control value
            JToken value = obj.GetValue("value");

            foreach (IGridConverter converter in GridContext.Current.Converters)
            {
                try {
                    IGridControlValue converted;
                    if (!converter.ConvertControlValue(control, value, out converted))
                    {
                        continue;
                    }
                    control.Value = converted;
                    break;
                } catch (Exception ex) {
                    global::Umbraco.Core.Composing.Current.Logger.Error <GridControl>(ex, "Converter of type " + converter + " failed for ConvertControlValue()");
                }
            }

            return(control);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a control from the specified <paramref name="obj"/>.
        /// </summary>
        /// <param name="area">The parent area of the control.</param>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        public static GridControl Parse(GridArea area, JObject obj)
        {
            // Set basic properties
            GridControl control = new GridControl(obj)
            {
                Area = area
            };

            // As of Umbraco 7.3, information about the editor is no longer saved in the JSON, since these should be read from the configuration
            if (UmbracoVersion.Current.Major == 7 && UmbracoVersion.Current.Minor >= 3)
            {
                Howdy.ReplaceEditorObjectFromConfig(control);
            }

            // Parse the editor
            control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x));

            // Parse the control value
            JToken value = obj.GetValue("value");

            foreach (IGridConverter converter in GridContext.Current.Converters)
            {
                try {
                    IGridControlValue converted;
                    if (!converter.ConvertControlValue(control, value, out converted))
                    {
                        continue;
                    }
                    control.Value = converted;
                    break;
                } catch (Exception ex) {
                    LogHelper.Error <GridControl>("Converter of type " + converter + " failed for ConvertControlValue()", ex);
                }
            }

            return(control);
        }