public AstType CreateShortType(ICompilation compilation, CSharpParsedFile parsedFile, TextLocation loc, IType fullType)
        {
            var csResolver = parsedFile.GetResolver(compilation, loc);
            var builder    = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder(csResolver);

            return(builder.ConvertType(fullType));
        }
Esempio n. 2
0
        List <string> GetUsedNamespaces()
        {
            var scope  = CSharpParsedFile.GetUsingScope(document.Editor.Caret.Location);
            var result = new List <string> ();

            while (scope != null)
            {
                result.Add(scope.NamespaceName);
                var ctx = CSharpParsedFile.GetResolver(Document.Compilation, scope.Region.Begin);
                foreach (var u in scope.Usings)
                {
                    var ns = u.ResolveNamespace(ctx);
                    if (ns == null)
                    {
                        continue;
                    }
                    result.Add(ns.FullName);
                }
                scope = scope.Parent;
            }
            return(result);
        }
Esempio n. 3
0
        protected Tuple <ResolveResult, CSharpResolver> ResolveExpression(AstNode expr, CompilationUnit unit)
        {
            if (expr == null)
            {
                return(null);
            }
            AstNode resolveNode;

            if (expr is Expression || expr is AstType)
            {
                resolveNode = expr;
            }
            else if (expr is VariableDeclarationStatement)
            {
                resolveNode = ((VariableDeclarationStatement)expr).Type;
            }
            else
            {
                resolveNode = expr;
            }
            try {
                var ctx  = CSharpParsedFile.GetResolver(Compilation, location);
                var root = expr.AncestorsAndSelf.FirstOrDefault(n => n is EntityDeclaration || n is CompilationUnit);
                if (root == null)
                {
                    return(null);
                }
                var csResolver = new CSharpAstResolver(ctx, root, CSharpParsedFile);
                var result     = csResolver.Resolve(resolveNode);
                var state      = csResolver.GetResolverStateBefore(resolveNode);
                return(Tuple.Create(result, state));
            } catch (Exception e) {
                Console.WriteLine(e);
                return(null);
            }
        }
Esempio n. 4
0
		public AstType CreateShortType (ICompilation compilation, CSharpParsedFile parsedFile, TextLocation loc, IType fullType)
		{
			var csResolver = parsedFile.GetResolver (compilation, loc);
			var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver);
			return builder.ConvertType (fullType);			
		}