Beispiel #1
0
        private FilterModelCollection BuildFilterFromExpression(TwoFactorExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            Debug.WriteLine(expression.ToString());
            FilterModelCollection collection = new FilterModelCollection();

            if (expression.OperatorToken.Text == "and")
            {
                collection.Operator = LogicOperator.And;
                if (expression.LeftExpression != null)
                {
                    var child = this.BuildFilterFromExpression(expression.LeftExpression);
                    collection.Filters.Add(child);
                }

                if (expression.RightExpression != null)
                {
                    var child = this.BuildFilterFromExpression(expression.RightExpression);
                    collection.Filters.Add(child);
                }
            }
            else if (expression.OperatorToken.Text == "or")
            {
                collection.Operator = LogicOperator.Or;
                if (expression.LeftExpression != null)
                {
                    var child = this.BuildFilterFromExpression(expression.LeftExpression);
                    collection.Filters.Add(child);
                }

                if (expression.RightExpression != null)
                {
                    var child = this.BuildFilterFromExpression(expression.RightExpression);
                    collection.Filters.Add(child);
                }
            }
            else
            {
                if (expression.LeftExpression.LeftExpression != null ||
                    expression.LeftExpression.RightExpression != null ||
                    expression.RightExpression.LeftExpression != null ||
                    expression.RightExpression.RightExpression != null)
                {
                    throw new ArgumentException(
                              "Non logic expression should not have sub expression",
                              nameof(expression));
                }
                FilterModel model = new FilterModel();
                model.Name     = expression.LeftExpression.ValueToken.Text;
                model.Value    = expression.RightExpression.ValueToken.Text;
                model.Operator = expression.OperatorToken.Text;
                collection.Filters.Add(model);
            }

            return(collection);
        }
        /// <summary>
        /// Clone object
        /// </summary>
        /// <returns>Cloned object</returns>
        public HudBumperStickerType Clone()
        {
            var clone = (HudBumperStickerType)MemberwiseClone();

            clone.Stats = new ObservableCollection <BaseHudRangeStat>(clone.Stats.Select(x => (BaseHudRangeStat)x.Clone()));
            clone.FilterModelCollection = FilterModelCollection != null && FilterModelCollection.Any()
                ? new IFilterModelCollection(FilterModelCollection?.Select(x => (IFilterModel)x.Clone()))
                : new IFilterModelCollection();

            return(clone);
        }
Beispiel #3
0
        public int GetFiltersHashCode()
        {
            unchecked
            {
                var hashcode = 23;

                FilterModelCollection.ForEach(model =>
                {
                    var modelHashCode = JsonConvert.SerializeObject(model);
                    hashcode          = (hashcode * 31) + modelHashCode.GetHashCode();
                });

                return(hashcode);
            }
        }