Example #1
0
 /// <summary>
 /// 添加一个属性匹配条件为一个单独的组。
 /// </summary>
 /// <param name="propertyMatch">The property match.</param>
 public void Add(PropertyMatch propertyMatch)
 {
     _groups.Add(new PropertyMatchGroup()
     {
         propertyMatch
     });
 }
Example #2
0
        /// <summary>
        /// 添加指定的属性匹配到组集合中。
        /// </summary>
        /// <param name="group"></param>
        /// <param name="item"></param>
        public void AddToGroup(IPropertyMatchGroup group, PropertyMatch item)
        {
            var realGroup = group as PropertyMatchGroup;

            //如果 group 不是一个真正的组,那么它就是一个 PropertyMatch。
            //这时再添加新的元素到这个组中,需要把它升级为一个真正的组集合。
            if (realGroup == null)
            {
                var index = _groups.IndexOf(group);
                if (index < 0)
                {
                    throw new InvalidOperationException("group 没有在本条件中,不能为其添加元素。请先将 group 添加到本条件中。");
                }
                realGroup = new PropertyMatchGroup {
                    group as PropertyMatch
                };
                _groups[index] = realGroup;
            }

            realGroup.Add(item);
        }
Example #3
0
        /// <summary>
        /// 添加一个属性匹配条件到最后一个组中。
        /// 如果此时不没有任何一个组,则会自动创建一个新组。
        /// </summary>
        /// <param name="propertyMatch">The property match.</param>
        public void AddToLastGroup(PropertyMatch propertyMatch)
        {
            var group = FindOrCreateGroup();

            this.AddToGroup(group, propertyMatch);
        }