Пример #1
0
        /// <exception cref="BadSyntaxException">
        /// The <paramref name="declaration"/> does not fit to the syntax.
        /// </exception>
        /// <exception cref="ReservedNameException">
        /// The parameter name is already exists.
        /// </exception>
        public override Parameter ModifyParameter(Parameter parameter, string declaration)
        {
            Match match = singleParamterRegex.Match(declaration);
            int   index = InnerList.IndexOf(parameter);

            if (index < 0)
            {
                return(parameter);
            }

            if (match.Success)
            {
                Group nameGroup     = match.Groups["name"];
                Group typeGroup     = match.Groups["type"];
                Group modifierGroup = match.Groups["modifier"];

                if (ReservedName(nameGroup.Value, index))
                {
                    throw new ReservedNameException(nameGroup.Value);
                }

                Parameter newParameter = new CSharpParameter(nameGroup.Value, typeGroup.Value,
                                                             SyntaxHelper.ParseParameterModifier(modifierGroup.Value));
                InnerList[index] = newParameter;
                return(newParameter);
            }
            else
            {
                throw new BadSyntaxException("error_invalid_parameter_declaration");
            }
        }
Пример #2
0
        /// <exception cref="BadSyntaxException">
        /// The <paramref name="declaration"/> does not fit to the syntax.
        /// </exception>
        public override void InitFromString(string declaration)
        {
            if (parameterStringRegex.IsMatch(declaration))
            {
                Clear();
                foreach (Match match in parameterRegex.Matches(declaration))
                {
                    Group nameGroup     = match.Groups["name"];
                    Group typeGroup     = match.Groups["type"];
                    Group modifierGroup = match.Groups["modifier"];

                    InnerList.Add(new CSharpParameter(nameGroup.Value, typeGroup.Value,
                                                      SyntaxHelper.ParseParameterModifier(modifierGroup.Value)));
                }
            }
            else
            {
                throw new BadSyntaxException("error_invalid_parameter_declaration");
            }
        }