/// <summary> /// Tries to determine the resource set which is referenced by the /// resource manager which is assigned to the specified member. /// </summary> /// <param name="member">The referenced member to examine.</param> /// <returns> /// The ResourceSetReference, if successful, or a null reference, if the /// specified member is not a resource manager or if the /// resource file cannot be determined. /// </returns> static ResourceSetReference ResolveResourceSet(IMember member) { if (member != null && member.ReturnType != null && member.DeclaringType != null && member.DeclaringType.CompilationUnit != null) { ResourceSetReference rsr; if (!NRefactoryAstCacheService.CacheEnabled || !cachedResourceSetReferenceMappings.TryGetValue(member, out rsr)) { string declaringFileName = member.DeclaringType.CompilationUnit.FileName; if (declaringFileName != null) { if (IsResourceManager(member.ReturnType, declaringFileName)) { SupportedLanguage?language = NRefactoryResourceResolver.GetFileLanguage(declaringFileName); if (language == null) { return(null); } CompilationUnit cu = NRefactoryAstCacheService.GetFullAst(language.Value, declaringFileName, ResourceResolverService.GetParsableFileContent(declaringFileName)); if (cu != null) { ResourceManagerInitializationFindVisitor visitor = new ResourceManagerInitializationFindVisitor(member); cu.AcceptVisitor(visitor, null); if (visitor.FoundResourceSet != null) { rsr = visitor.FoundResourceSet; if (NRefactoryAstCacheService.CacheEnabled) { cachedResourceSetReferenceMappings.Add(member, rsr); } return(rsr); } } } } return(null); } return(rsr); } return(null); }
// ******************************************************************************************************************************** /// <summary> /// Parses an expression with NRefactory. /// </summary> /// <param name="fileName">The file name of the source code file that contains the expression.</param> /// <param name="expression">The expression to parse.</param> /// <param name="caretLine">The 1-based line number of the expression.</param> /// <param name="caretColumn">The 1-based column number of the expression.</param> /// <returns>The parsed expression or <c>null</c> if the expression cannot be parsed or the language of the source code file is not supported.</returns> public static Expression ParseExpression(string fileName, string expression, int caretLine, int caretColumn) { SupportedLanguage?l = NRefactoryResourceResolver.GetFileLanguage(fileName); if (l == null) { return(null); } using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser(l.Value, new System.IO.StringReader(expression))) { Expression expr = p.ParseExpression(); if (expr != null) { expr.AcceptVisitor(new SetAllNodePointsAstVisitor(new Location(caretColumn, caretLine), new Location(caretColumn + 1, caretLine)), null); } return(expr); } }