Example #1
0
        /// <summary>
        /// 深度复制集合
        /// </summary>
        /// <returns>复制后的集合</returns>
        public virtual OptionCollection Clone()
        {
            OptionCollection collection = new OptionCollection(this.UniqueKey);

            foreach (Option setting in this.Values)
            {
                collection.Add(setting.Clone()).Parent = setting.Parent;
            }
            return(collection);
        }
Example #2
0
        /// <summary>
        /// 编译本选项节,将执行一些选项命令,具有选项命令的选项节需执行本方法后才可以使用
        /// </summary>
        /// <param name="current">当前选项节</param>
        /// <param name="settings">选项命令集合</param>
        /// <returns>编译后的选项节</returns>
        protected static Option Compile(Option current, OptionCollection settings)
        {
            OptionCollection currentSettings = current.childSettings;

            if (settings.Count > 0)
            {
                for (int i = 0; i < settings.Count; i++)
                {
                    Option setting = settings[i];
                    switch (setting.SettingOperator)
                    {
                    case OptionOperatorEnum.Add:
                        if (currentSettings.Contains(setting.Name))
                        {
                            throw new OptionException(string.Format("已存在子选项节 {0}", setting.Name));
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;

                    case OptionOperatorEnum.Remove:
                        currentSettings.Remove(setting.Name);
                        break;

                    case OptionOperatorEnum.Move:
                        Option moveSetting = currentSettings[setting.Name];
                        if (moveSetting != null)
                        {
                            currentSettings.Remove(moveSetting.Name);
                            currentSettings.Add(moveSetting);
                        }
                        break;

                    case OptionOperatorEnum.Clear:
                        currentSettings.Clear();
                        break;

                    case OptionOperatorEnum.Update:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        break;

                    case OptionOperatorEnum.Set:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;

                    default:
                        if (currentSettings.Contains(setting.Name))
                        {
                            currentSettings[setting.Name].Merge(setting);
                        }
                        else
                        {
                            currentSettings.Add(setting).Parent = current;
                        }
                        break;
                    }
                }
            }
            return(current);
        }