当前位置: 首页>>代码示例>>C#>>正文


C# VBAParser.argCall方法代码示例

本文整理汇总了C#中VBAParser.argCall方法的典型用法代码示例。如果您正苦于以下问题:C# VBAParser.argCall方法的具体用法?C# VBAParser.argCall怎么用?C# VBAParser.argCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VBAParser的用法示例。


在下文中一共展示了VBAParser.argCall方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RewriteCall

        private void RewriteCall(VBAParser.ArgsCallContext paramList, CodeModule module)
        {
            var paramNames = paramList.argCall().Select(arg => arg.GetText()).ToList();
            var lineCount = paramList.Stop.Line - paramList.Start.Line + 1; // adjust for total line count

            var newContent = module.Lines[paramList.Start.Line, lineCount].Replace(" _" + Environment.NewLine, string.Empty).RemoveExtraSpacesLeavingIndentation();

            var parameterIndex = 0;
            var currentStringIndex = 0;

            for (var i = 0; i < paramNames.Count && parameterIndex < _model.Parameters.Count; i++)
            {
                var parameterStringIndex = newContent.IndexOf(paramNames.ElementAt(i), currentStringIndex, StringComparison.Ordinal);

                if (parameterStringIndex <= -1) { continue; }

                var oldParameterString = paramNames.ElementAt(i);
                var newParameterString = paramNames.ElementAt(_model.Parameters.ElementAt(parameterIndex).Index);
                var beginningSub = newContent.Substring(0, parameterStringIndex);
                var replaceSub = newContent.Substring(parameterStringIndex).Replace(oldParameterString, newParameterString);

                newContent = beginningSub + replaceSub;

                parameterIndex++;
                currentStringIndex = beginningSub.Length + newParameterString.Length;
            }

            module.ReplaceLine(paramList.Start.Line, newContent);
            module.DeleteLines(paramList.Start.Line + 1, lineCount - 1);
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:30,代码来源:ReorderParametersRefactoring.cs

示例2: RemoveCallParameter

        private void RemoveCallParameter(VBAParser.ArgsCallContext paramList, CodeModule module)
        {
            var paramNames = paramList.argCall().Select(arg => arg.GetText()).ToList();
            var lineCount = paramList.Stop.Line - paramList.Start.Line + 1; // adjust for total line count

            var newContent = module.Lines[paramList.Start.Line, lineCount].Replace(" _", "").RemoveExtraSpaces();
            var currentStringIndex = 0;

            foreach (
                var param in
                    _model.Parameters.Where(item => item.IsRemoved && item.Index < paramNames.Count)
                        .Select(item => item.Declaration))
            {
                var paramIndex = _model.Parameters.FindIndex(item => item.Declaration.Context.GetText() == param.Context.GetText()); 
                if (paramIndex >= paramNames.Count) { return; }

                do
                {
                    var paramToRemoveName = paramNames.ElementAt(0).Contains(":=")
                        ? paramNames.Find(item => item.Contains(param.IdentifierName + ":="))
                        : paramNames.ElementAt(paramIndex);

                    if (paramToRemoveName == null || !newContent.Contains(paramToRemoveName))
                    {
                        continue;
                    }

                    var valueToRemove = paramToRemoveName != paramNames.Last()
                        ? paramToRemoveName + ","
                        : paramToRemoveName;

                    var parameterStringIndex = newContent.IndexOf(valueToRemove, currentStringIndex, StringComparison.Ordinal);
                    if (parameterStringIndex <= -1) { continue; }

                    newContent = newContent.Remove(parameterStringIndex, valueToRemove.Length);

                    currentStringIndex = parameterStringIndex;

                    if (paramToRemoveName == paramNames.Last() && newContent.LastIndexOf(',') != -1)
                    {
                        newContent = newContent.Remove(newContent.LastIndexOf(','), 1);
                    }
                } while (paramIndex >= _model.Parameters.Count - 1 && ++paramIndex < paramNames.Count &&
                         newContent.Contains(paramNames.ElementAt(paramIndex)));
            }

            module.ReplaceLine(paramList.Start.Line, newContent);
            for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineCount; line++)
            {
                module.ReplaceLine(line, "");
            }
        }
开发者ID:ThunderFrame,项目名称:Rubberduck,代码行数:52,代码来源:RemoveParametersRefactoring.cs


注:本文中的VBAParser.argCall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。