Beispiel #1
0
        private ComplexEnumeration ParseEnumeration(string portEnumeration)
        {
            var newEnumeration = new ComplexEnumeration();
            var to             = "(downto|to)";
            var directionStr   = Regex.Match(portEnumeration, to).Value;
            EnumerationDirections direction;

            if (!EnumerationDirections.TryParse(directionStr, true, out direction))
            {
                return(null);
            }
            newEnumeration.Direction = direction;

            var leftNumber  = Num + "(?=" + MFS + to + ")";
            var rightNumber = "(?<=" + to + MFS + ")" + Num;

            int left, right;
            var leftStr  = Regex.Match(portEnumeration, leftNumber).Value;
            var rightStr = Regex.Match(portEnumeration, rightNumber).Value;

            if (!int.TryParse(leftStr, out left))
            {
                throw new Exception("!!!");
            }
            if (!int.TryParse(rightStr, out right))
            {
                throw new Exception("!!!");
            }
            newEnumeration.From = left;
            newEnumeration.To   = right;


            return(newEnumeration);
        }
        public static ComplexEnumeration Parse(string text)
        {
            var                   newEnumeration = new ComplexEnumeration();
            const string          to             = "(downto|to)";
            var                   directionStr   = Regex.Match(text, to).Value;
            EnumerationDirections direction;

            if (!EnumerationDirections.TryParse(directionStr, true, out direction))
            {
                return(null);
            }

            newEnumeration.Direction = direction;

            var leftNumber  = PC.Num + "(?=" + PC.MFS + to + ")";
            var rightNumber = "(?<=" + to + PC.MFS + ")" + PC.Num;

            int left, right;
            var leftStr  = Regex.Match(text, leftNumber).Value;
            var rightStr = Regex.Match(text, rightNumber).Value;

            if (!int.TryParse(leftStr, out left))
            {
                return(null);
            }
            if (!int.TryParse(rightStr, out right))
            {
                return(null);
            }
            newEnumeration.From = left;
            newEnumeration.To   = right;

            return(newEnumeration);
        }
 public ComplexEnumeration(int n, EnumerationDirections direction)
 {
     Direction = direction;
     if (direction == EnumerationDirections.To)
     {
         From = 0;
         To   = n - 1;
     }
     if (direction == EnumerationDirections.Downto)
     {
         To   = 0;
         From = n - 1;
     }
 }
 public ComplexEnumeration(int from, int to, EnumerationDirections directions)
 {
     From      = from;
     To        = to;
     Direction = directions;
 }