本文整理汇总了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);
}
示例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, "");
}
}