本文整理汇总了C#中IFile.GetDocumentRange方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.GetDocumentRange方法的具体用法?C# IFile.GetDocumentRange怎么用?C# IFile.GetDocumentRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFile
的用法示例。
在下文中一共展示了IFile.GetDocumentRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallExtensionMethodsAsStatic
private static void CallExtensionMethodsAsStatic(IFile file, INamespace importedNs, CSharpElementFactory factory)
{
var targetsCollector = new TypeUsagesCollector(file, file.GetDocumentRange());
var references = targetsCollector.Run();
foreach (var reference in references)
{
var resolve = reference.Resolve();
var declaredElement = resolve.DeclaredElement;
var imethod = declaredElement as IMethod;
var methodExecution = reference.GetTreeNode();
var method = methodExecution as IReferenceExpression;
var containingNsQualifiedName =
imethod.IfNotNull(m => m.GetContainingType())
.IfNotNull(t => t.GetContainingNamespace())
.IfNotNull(ns => ns.QualifiedName);
if (imethod != null && method.IsExtensionMethod() && containingNsQualifiedName == importedNs.QualifiedName)
{
var invocate = InvocationExpressionNavigator.GetByInvokedExpression(method);
//if (invocate == null) return null;
// build string like $0($1,$2,..argc)
var tokens = string.Format(
"$0({0})",
string.Join(
",",
new[] { "$1" }.Concat(invocate.Arguments.Select((a, i) => "$" + (i + 2).ToString("G"))).ToArray()));
var funcAndThis = new object[] { "faketobind", (invocate.InvokedExpression as IReferenceExpression).QualifierExpression };
var paramsObject = funcAndThis.Concat(invocate.Arguments).ToArray();
var cSharpExpression = (IInvocationExpression)factory.CreateExpression(tokens, paramsObject);
var replaceResult = invocate.ReplaceBy(cSharpExpression);
(replaceResult.InvokedExpression as IReferenceExpression).Reference.BindTo(declaredElement);
}
}
}