예제 #1
0
        public Metric.Axis ParseAxis(string expression, int exponent)
        {
            Unit   unit   = null;
            Prefix prefix = null;


            unit = FindUnit(expression);
            if (unit == null)
            {
                prefix = GetPrefix(expression);
                if (prefix == null)
                {
                    throw new ArgumentException(string.Format("Unknown Unit or prefix in expression '{0}'", expression));
                }

                int    count = prefix.Symbol.Length;
                string s     = expression.Remove(0, count);
                unit = FindUnit(s);

                if (unit == null)
                {
                    throw new ArgumentException(string.Format("Unknown Unit or prefix in expression '{0}'", expression));
                }
            }
            Metric.Axis component = (unit != null) ? new Metric.Axis(prefix, unit, exponent) : null;
            return(component);
        }
예제 #2
0
        public Metric ParseMetric(IEnumerable <Unary> tokens)
        {
            List <Metric.Axis> components = new List <Metric.Axis>();

            foreach (Unary u in tokens)
            {
                Metric.Axis component = ParseAxis(u.Expression, u.Exponent);
                components.Add(component);
            }
            return(new Metric(components));
        }
예제 #3
0
 public override bool Equals(object obj)
 {
     if (obj is Metric.Axis)
     {
         Metric.Axis c = (Metric.Axis)obj;
         return
             ((this.Prefix == c.Prefix)
              &&
              (this.Unit == c.Unit));
     }
     else
     {
         return(false);
     }
 }