public static bool AddBracketIfIsFirstInstance(this LineEvaluationModel model, BracketInfoModel bracketInfo)
        {
            if (model.Brackets.ContainsKey(bracketInfo.Type)) return false;

            var bracketTracker = new BracketTracker
            {
                AmountOpen = bracketInfo.IsOpener ? 1 : 0,
                AmountClosed = bracketInfo.IsOpener ? 0 : 1,
            };

            if (bracketTracker.AmountOpen == 0 && bracketTracker.AmountClosed > 0)
            {
                throw new ArgumentException(string.Format("Attempted to add a closing {0} without an opening equivalent", bracketInfo.Type));
            }

            model.Brackets.Add(bracketInfo.Type, bracketTracker);
            return true;
        }
        public static BracketInfoModel GetBracketInfo(this char character)
        {
            var result = new BracketInfoModel { Type = BracketType.NotABracket };

            foreach (var bracketDefintion in BracketDefintions)
            {
                if (bracketDefintion.Opener == character)
                {
                    result.IsOpener = true;
                    result.Type = bracketDefintion.BracketType;
                }
                else if (bracketDefintion.Closer == character)
                {
                    result.IsOpener = false;
                    result.Type = bracketDefintion.BracketType;
                }
            }

            return result;
        }
示例#3
0
        public static BracketInfoModel GetBracketInfo(this char character)
        {
            var result = new BracketInfoModel {
                Type = BracketType.NotABracket
            };

            foreach (var bracketDefintion in BracketDefintions)
            {
                if (bracketDefintion.Opener == character)
                {
                    result.IsOpener = true;
                    result.Type     = bracketDefintion.BracketType;
                }
                else if (bracketDefintion.Closer == character)
                {
                    result.IsOpener = false;
                    result.Type     = bracketDefintion.BracketType;
                }
            }

            return(result);
        }