Beispiel #1
0
        public string ApplyConversionRule(string sourceCode, ConversionParameters conversionParameters)
        {
            Logger.AddApplyConversionRuleEntryLog(RuleName, RuleType, RuleTypePriority);

            var match = Regex.Match(sourceCode, RuleApplicablePattern);

            if (match.Success)
            {
                Logger.AddSourceCode(match.Value);

                string leadingSpace     = match.Groups["leadingSpace"].ToString();
                string methodName       = match.Groups["methodName"].ToString();
                string methodParameters = match.Groups["methodParameters"].ConvertToString();
                string comments         = match.Groups["comments"].ConvertToString();

                conversionParameters.AddMethodName(leadingSpace, methodName, comments);

                foreach (var variableNameWithSpace in methodParameters.Split(','))
                {
                    string variableName = variableNameWithSpace.Trim();
                    conversionParameters.AddMethodParameters(Utility.GetType(variableName), variableName);
                }

                sourceCode = sourceCode.Remove(match.Index, match.Length);

                if (sourceCode.Length > 0 && sourceCode.Substring(0, 1) == "\n")
                {
                    sourceCode = sourceCode.Remove(0, 1);
                }
                return(sourceCode);
            }

            Logger.AddLog("MatchFailed");
            return(sourceCode);
        }
        public string ApplyConversionRule(string sourceCode, ConversionParameters conversionParameters)
        {
            Logger.AddApplyConversionRuleEntryLog(RuleName, RuleType, RuleTypePriority);

            var match = Regex.Match(sourceCode, RuleApplicablePattern);

            if (match.Success)
            {
                Logger.AddSourceCode(match.Value);

                string leadingSpace   = match.Groups["leadingSpace"].ToString();
                int    parameterCount = match.Groups["parameterCount"].ConvertToInt32();
                string parameterName  = match.Groups["parameterName"].ToString();
                string defaultValue   = match.Groups["defaultValue"].ConvertToString();

                conversionParameters.AddOptionalParameterValue(parameterName, defaultValue, parameterCount);

                sourceCode = sourceCode.Remove(match.Index, match.Length);

                if (sourceCode.Length > 0 && sourceCode.Substring(0, 1) == "\n")
                {
                    sourceCode = sourceCode.Remove(0, 1);
                }
                return(sourceCode);
            }

            Logger.AddLog("MatchFailed");
            return(sourceCode);
        }
        public string ApplyConversionRule(string sourceCode, ConversionParameters conversionParameters)
        {
            Logger.AddApplyConversionRuleEntryLog(RuleName, RuleType, RuleTypePriority);

            var match = Regex.Match(sourceCode, RuleApplicablePattern);

            if (match.Success)
            {
                Logger.AddSourceCode(match.Value);

                string leadingSpace = match.Groups["leadingSpace"].ToString();
                //string variableName =

                StringBuilder convertedCodeBuilder       = new StringBuilder();
                Dictionary <string, string> groupBuilder = new Dictionary <string, string>();
                foreach (Match subMatch in Regex.Matches(match.Value, SubPattern))
                {
                    string variableName = subMatch.Groups["variableName"].Value;


                    Utility.ConvertVariables(conversionParameters, groupBuilder, convertedCodeBuilder, variableName, leadingSpace, true);
                }

                if (conversionParameters.IsLocalVariableGroupingRequired)
                {
                    foreach (KeyValuePair <string, string> keyValuePair in groupBuilder)
                    {
                        convertedCodeBuilder.AppendLine(leadingSpace + keyValuePair.Key + " " + keyValuePair.Value + ";");
                    }
                }

                string convertedCode = convertedCodeBuilder.ToString();
                conversionParameters.AddConvertedCode(convertedCode);

                Logger.AddConvertedCode(convertedCode);

                sourceCode = sourceCode.Remove(match.Index, match.Length);

                if (sourceCode.Length > 0 && sourceCode.Substring(0, 1) == "\n")
                {
                    sourceCode = sourceCode.Remove(0, 1);
                }
                return(sourceCode);
            }

            Logger.AddLog("MatchFailed");
            return(sourceCode);
        }