Ejemplo n.º 1
0
        /// <summary>
        /// 增加Widget
        /// </summary>
        /// <returns></returns>
        public IDynamicPage AddWidget(IDynamicWidget widget)
        {
            if (widget == null)
            {
                throw new ArgumentException("参数widget不能为null");
            }

            if (string.IsNullOrWhiteSpace(widget.WidgetPath))
            {
                throw new ArgumentException("参数widget.WidgetPath不能为null");
            }

            var any = Widgets.Any(x => widget.WidgetPath.NbEquals(x.WidgetPath));

            if (any)
            {
                throw new ArgumentException("不能重复添加组件:" + widget.WidgetPath);
            }

            Widgets.Add(widget);
            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 替换Widget
        /// </summary>
        /// <param name="widget"></param>
        /// <returns></returns>
        public IDynamicPage AddOrReplaceWidget(IDynamicWidget widget)
        {
            if (widget == null)
            {
                throw new ArgumentException("参数widget不能为null");
            }

            if (string.IsNullOrWhiteSpace(widget.WidgetPath))
            {
                throw new ArgumentException("参数widget.WidgetPath不能为null");
            }
            var fixWidgetPath = widget.WidgetPath;

            var any = Widgets.Any(x => widget.WidgetPath.NbEquals(x.WidgetPath));

            if (!any)
            {
                Widgets.Add(widget);
                return(this);
            }

            int indexOfWidget = -1;

            for (var i = 0; i < Widgets.Count; i++)
            {
                var dynamicWidget = Widgets[i];
                if (fixWidgetPath.NbEquals(dynamicWidget.WidgetPath))
                {
                    indexOfWidget = i;
                    break;
                }
            }

            Widgets[indexOfWidget] = widget;
            return(this);
        }