#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.5 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Threading.Tasks;
using CSharpBinding.Parser;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.SharpDevelop.Refactoring;
namespace CSharpBinding
{
/// <summary>
/// C#-specific extension methods.
/// </summary>
public static class ExtensionMethods
{
public static async Task<CompilationUnit> GetCompilationUnitAsync(this EditorRefactoringContext editorContext)
{
var parseInfo = (await editorContext.GetParseInformationAsync().ConfigureAwait(false)) as CSharpFullParseInformation;
if (parseInfo != null)
return parseInfo.CompilationUnit;
else
return new CompilationUnit();
}
public static Task<CSharpAstResolver> GetAstResolverAsync(this EditorRefactoringContext editorContext)
{
return editorContext.GetCachedAsync(
async ec => {
var parseInfo = (await ec.GetParseInformationAsync().ConfigureAwait(false)) as CSharpFullParseInformation;
var compilation = await ec.GetCompilationAsync().ConfigureAwait(false);
if (parseInfo != null)
return parseInfo.GetResolver(compilation);
else
return new CSharpAstResolver(compilation, new CompilationUnit(), new CSharpParsedFile(ec.FileName));
});
}
}
}