Esempio n. 1
0
        protected List <ParsedParams> TryParseParams(string parameters)
        {
            parameters = ParamNormRegex.Replace(parameters, string.Empty);
            parameters = parameters.Trim();
            if (string.IsNullOrEmpty(parameters))
            {
                return(new List <ParsedParams>());
            }

            var typeMatches = ParamTypeRegex.Matches(parameters);
            var nameMatches = ParamNameRegex.Matches(parameters);

            if (typeMatches.Count != nameMatches.Count)
            {
                throw new InvalidCastException();
            }

            var rez = new List <ParsedParams>();

            for (var i = 0; i < typeMatches.Count; i++)
            {
                var defaultValue = string.Empty;
                var name         = nameMatches[i].Value;
                var eqv          = name.IndexOf("=", StringComparison.Ordinal);
                if (eqv > -1)
                {
                    defaultValue = name.Substring(eqv + 1).Trim();
                    name         = name.Remove(eqv).Trim();
                }

                var param = new ParsedParams()
                {
                    CppName = name,
                    Name    = CashParser.ToTitleCase(name, false),
                    Default = defaultValue,
                    CppType = typeMatches[i].Value,
                    Type    = GetKnownTypeOrDefault(typeMatches[i].Value)
                };
                rez.Add(param);
            }

            return(rez);
        }
Esempio n. 2
0
        private ParsedParams TryParseParam(string parameters)
        {
            parameters = ParamNormRegex.Replace(parameters, string.Empty);
            parameters = parameters.Trim();
            if (string.IsNullOrEmpty(parameters))
            {
                return(new ParsedParams());
            }

            var typeMatche = ParamTypeRegex.Match(parameters);
            var nameMatche = ParamNameRegex.Match(parameters);

            if (!typeMatche.Success || !nameMatche.Success)
            {
                throw new InvalidCastException();
            }

            var defaultValue = string.Empty;
            var name         = nameMatche.Value;
            var eqv          = name.IndexOf("=", StringComparison.Ordinal);

            if (eqv > -1)
            {
                defaultValue = name.Substring(eqv + 1).Trim();
                name         = name.Remove(eqv).Trim();
            }

            var rez = new ParsedParams()
            {
                CppName = name,
                Name    = CashParser.ToTitleCase(name, false),
                Default = defaultValue,
                CppType = typeMatche.Value,
                Type    = GetKnownTypeOrDefault(typeMatche.Value)
            };

            return(rez);
        }