static bool DimensionsAreEqual(UIExchangeItem x, UIExchangeItem y)
 {
     return(x.ValueDefinition is IQuantity &&
            y.ValueDefinition is IQuantity &&
            Dimension.DescribesSameAs(((IQuantity)x.ValueDefinition).Unit.Dimension,
                                      ((IQuantity)y.ValueDefinition).Unit.Dimension));
 }
示例#2
0
        public void Equals()
        {
            Dimension dimension = new Dimension();

            dimension.SetPower(DimensionBase.Length, 3);
            dimension.SetPower(DimensionBase.Time, -1);

            Assert.IsTrue(Dimension.DescribesSameAs(dimension, this.dimension));
            dimension.SetPower(DimensionBase.Length, 2);
            Assert.IsFalse(Dimension.DescribesSameAs(dimension, this.dimension));

            Assert.IsFalse(dimension.Equals("string"));
        }
            public bool Predicate(UIExchangeItem item)
            {
                if (!(item.ValueDefinition is IQuantity))
                {
                    return(false);
                }

                foreach (IDimension d in _dimensions)
                {
                    if (Dimension.DescribesSameAs(d, ((IQuantity)item.ValueDefinition).Unit.Dimension))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            public FilterOnDimension(List <UIExchangeItem> items)
            {
                if (items.Count > 0)
                {
                    CompareDimensions compare = new CompareDimensions();

                    items.Sort(compare);

                    for (int n = 0; n < items.Count; ++n)
                    {
                        if (items[n].ValueDefinition is IQuantity)
                        {
                            if (_dimensions.Count == 0 ||
                                !Dimension.DescribesSameAs(_dimensions[_dimensions.Count - 1],
                                                           ((IQuantity)items[n].ValueDefinition).Unit.Dimension))
                            {
                                _dimensions.Add(((IQuantity)items[n].ValueDefinition).Unit.Dimension);
                            }
                        }
                    }
                }
            }