本文整理汇总了C#中Mono.LocationToOffset方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.LocationToOffset方法的具体用法?C# Mono.LocationToOffset怎么用?C# Mono.LocationToOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono
的用法示例。
在下文中一共展示了Mono.LocationToOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItem
public override TooltipItem GetItem (Mono.TextEditor.TextEditor editor, int offset)
{
var doc = IdeApp.Workbench.ActiveDocument;
if (doc == null || doc.ParsedDocument == null)
return null;
var unit = doc.ParsedDocument.GetAst<SyntaxTree> ();
if (unit == null)
return null;
var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;
if (file == null)
return null;
ResolveResult result;
AstNode node;
var loc = editor.OffsetToLocation (offset);
if (!doc.TryResolveAt (loc, out result, out node)) {
if (node is CSharpTokenNode) {
int startOffset2 = editor.LocationToOffset (node.StartLocation);
int endOffset2 = editor.LocationToOffset (node.EndLocation);
return new TooltipItem (new ToolTipData (unit, result, node, null), startOffset2, endOffset2 - startOffset2);
}
return null;
}
if (node == lastNode)
return lastResult;
var resolver = new CSharpAstResolver (doc.Compilation, unit, file);
resolver.ApplyNavigator (new NodeListResolveVisitorNavigator (node), CancellationToken.None);
var hoverNode = node.GetNodeAt (loc) ?? node;
int startOffset = editor.LocationToOffset (hoverNode.StartLocation);
int endOffset = editor.LocationToOffset (hoverNode.EndLocation);
return lastResult = new TooltipItem (new ToolTipData (unit, result, node, resolver), startOffset, endOffset - startOffset);
}
示例2: GetReference
MemberReference GetReference (ResolveResult result, AstNode node, string fileName, Mono.TextEditor.TextEditorData editor)
{
if (result == null) {
return null;
}
object valid = null;
if (result is MethodGroupResolveResult) {
valid = ((MethodGroupResolveResult)result).Methods.FirstOrDefault (m => searchedMembers.Any (member => member is IMethod && ((IMethod)member).Region == m.Region));
} else if (result is MemberResolveResult) {
var foundMember = ((MemberResolveResult)result).Member;
valid = searchedMembers.FirstOrDefault (member => member is IMember && ((IMember)member).Region == foundMember.Region);
} else if (result is NamespaceResolveResult) {
var ns = ((NamespaceResolveResult)result).NamespaceName;
valid = searchedMembers.FirstOrDefault (n => n is string && n.ToString () == ns);
} else if (result is LocalResolveResult) {
var ns = ((LocalResolveResult)result).Variable;
valid = searchedMembers.FirstOrDefault (n => n is IVariable && ((IVariable)n).Region == ns.Region);
} else if (result is TypeResolveResult) {
valid = searchedMembers.FirstOrDefault (n => n is IType);
} else {
valid = searchedMembers.FirstOrDefault ();
}
if (node is ConstructorInitializer)
return null;
if (node is ObjectCreateExpression)
node = ((ObjectCreateExpression)node).Type;
if (node is InvocationExpression)
node = ((InvocationExpression)node).Target;
if (node is MemberReferenceExpression)
node = ((MemberReferenceExpression)node).MemberNameToken;
if (node is MemberType)
node = ((MemberType)node).MemberNameToken;
if (node is TypeDeclaration && (searchedMembers.First () is IType))
node = ((TypeDeclaration)node).NameToken;
if (node is EntityDeclaration && (searchedMembers.First () is IMember))
node = ((EntityDeclaration)node).NameToken;
if (node is ParameterDeclaration && (searchedMembers.First () is IParameter))
node = ((ParameterDeclaration)node).NameToken;
if (node is ConstructorDeclaration)
node = ((ConstructorDeclaration)node).NameToken;
if (node is DestructorDeclaration)
node = ((DestructorDeclaration)node).NameToken;
var region = new DomRegion (fileName, node.StartLocation, node.EndLocation);
var length = node is PrimitiveType ? keywordName.Length : node.EndLocation.Column - node.StartLocation.Column;
return new MemberReference (valid, region, editor.LocationToOffset (region.Begin), length);
}
示例3: GetReference
MemberReference GetReference (Project project, ResolveResult result, AstNode node, SyntaxTree syntaxTree, string fileName, Mono.TextEditor.TextEditorData editor)
{
AstNode originalNode = node;
if (result == null)
return null;
object valid = null;
if (result is MethodGroupResolveResult) {
valid = ((MethodGroupResolveResult)result).Methods.FirstOrDefault (
m => searchedMembers.Any (member => member is IMethod && ((IMethod)member).Region == m.Region));
} else if (result is MemberResolveResult) {
var foundMember = ((MemberResolveResult)result).Member;
valid = searchedMembers.FirstOrDefault (
member => member is IMember && ((IMember)member).Region == foundMember.Region);
} else if (result is NamespaceResolveResult) {
var ns = ((NamespaceResolveResult)result).Namespace;
valid = searchedMembers.FirstOrDefault (n => n is INamespace && ns.FullName.StartsWith (((INamespace)n).FullName, StringComparison.Ordinal));
if (!(node is NamespaceDeclaration))
goto skip;
} else if (result is LocalResolveResult) {
var ns = ((LocalResolveResult)result).Variable;
valid = searchedMembers.FirstOrDefault (n => n is IVariable && ((IVariable)n).Region == ns.Region);
} else if (result is TypeResolveResult) {
valid = searchedMembers.FirstOrDefault (n => n is IType);
}
if (node is ConstructorInitializer)
return null;
if (node is ObjectCreateExpression)
node = ((ObjectCreateExpression)node).Type;
if (node is IndexerDeclaration)
node = ((IndexerDeclaration)node).ThisToken;
if (node is InvocationExpression)
node = ((InvocationExpression)node).Target;
if (node is MemberReferenceExpression)
node = ((MemberReferenceExpression)node).MemberNameToken;
if (node is SimpleType)
node = ((SimpleType)node).IdentifierToken;
if (node is MemberType)
node = ((MemberType)node).MemberNameToken;
if (node is NamespaceDeclaration) {
var nsd = ((NamespaceDeclaration)node);
node = nsd.NamespaceName;
if (node == null)
return null;
}
if (node is TypeDeclaration && (searchedMembers.First () is IType))
node = ((TypeDeclaration)node).NameToken;
if (node is DelegateDeclaration)
node = ((DelegateDeclaration)node).NameToken;
if (node is EntityDeclaration && (searchedMembers.First () is IMember))
node = ((EntityDeclaration)node).NameToken;
if (node is ParameterDeclaration && (searchedMembers.First () is IParameter))
node = ((ParameterDeclaration)node).NameToken;
if (node is ConstructorDeclaration)
node = ((ConstructorDeclaration)node).NameToken;
if (node is DestructorDeclaration)
node = ((DestructorDeclaration)node).NameToken;
if (node is NamedArgumentExpression)
node = ((NamedArgumentExpression)node).NameToken;
if (node is NamedExpression)
node = ((NamedExpression)node).NameToken;
if (node is VariableInitializer)
node = ((VariableInitializer)node).NameToken;
if (node is IdentifierExpression) {
node = ((IdentifierExpression)node).IdentifierToken;
}
skip:
var region = new DomRegion (fileName, node.StartLocation, node.EndLocation);
var length = node is PrimitiveType ? keywordName.Length : node.EndLocation.Column - node.StartLocation.Column;
if (valid == null)
valid = searchedMembers.FirstOrDefault ();
var reference = new CSharpMemberReference (project, originalNode, syntaxTree, valid, region, editor.LocationToOffset (region.Begin), length);
reference.ReferenceUsageType = GetUsage (originalNode);
return reference;
}