本文整理汇总了C#中EditorContext.GetClassDeclarationsOnCurrentLine方法的典型用法代码示例。如果您正苦于以下问题:C# EditorContext.GetClassDeclarationsOnCurrentLine方法的具体用法?C# EditorContext.GetClassDeclarationsOnCurrentLine怎么用?C# EditorContext.GetClassDeclarationsOnCurrentLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EditorContext
的用法示例。
在下文中一共展示了EditorContext.GetClassDeclarationsOnCurrentLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(EditorContext context)
{
// class at caret (either declaration of usage)
this.Class = GetClass(context.CurrentSymbol);
if (this.Class == null)
return;
var c = this.Class;
// TODO cache
var classDecls = context.GetClassDeclarationsOnCurrentLine().ToList();
this.IsCaretAtClassDeclaration = classDecls.Count == 1 && (classDecls[0].FullyQualifiedName == c.FullyQualifiedName);
this.IsClassFileNameCorrect = (c.IsInnerClass() || (!c.IsUserCode()) ||
c.Name.Equals(Path.GetFileNameWithoutExtension(c.CompilationUnit.FileName), StringComparison.OrdinalIgnoreCase));
if (string.IsNullOrEmpty(c.Name) || c.CompilationUnit == null || string.IsNullOrEmpty(c.CompilationUnit.FileName)) {
// Cannot get path
this.CorrectClassFileName = null;
this.IsCorrectClassFileNameAvailable = false;
return;
}
this.CorrectClassFileName = Path.Combine(Path.GetDirectoryName(c.CompilationUnit.FileName),
c.Name + Path.GetExtension(c.CompilationUnit.FileName));
this.IsCorrectClassFileNameAvailable = (FileUtility.IsValidPath(CorrectClassFileName)
&& Path.IsPathRooted(CorrectClassFileName)
&& !File.Exists(CorrectClassFileName));
this.IsClassReadOnly = FindReferencesAndRenameHelper.IsReadOnly(this.Class);
}
示例2: GetAvailableActions
public override IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext)
{
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine().Where(c => c.ClassType == ClassType.Class).Select(c2 => c2.GetCurrentClassPart(editorContext.Editor.FileName))) {
foreach (var implementAction in RefactoringService.GetImplementAbstractClassActions(targetClass)) {
yield return implementAction;
}
}
}
示例3: GetAvailableActions
public override IEnumerable<IContextAction> GetAvailableActions(EditorContext editorContext)
{
// Using CurrentLineAST is basically OK, but when the "class" keyword is on different line than class name,
// parsing only one line never tells us that we are looking at TypeDeclaration
// Alternative solution could be to try to resolve also IdentifierExpression to see if it is class declaration.
foreach (var targetClass in editorContext.GetClassDeclarationsOnCurrentLine()
.Where(c => c.ClassType == ClassType.Class || c.ClassType == ClassType.Interface)
.Select(c2 => c2.GetCurrentClassPart(editorContext.Editor.FileName))) {
foreach (var implementAction in RefactoringService.GetImplementInterfaceActions(targetClass)) {
yield return implementAction;
}
}
}