private static Type FindTypeMatchingMovedTypeBasedOnNamespaceFromError(IEnumerable <string> lines) { string valueFromNormalizedMessage = APIUpdaterHelper.GetValueFromNormalizedMessage(lines, "Line="); int num = (valueFromNormalizedMessage == null) ? -1 : int.Parse(valueFromNormalizedMessage); valueFromNormalizedMessage = APIUpdaterHelper.GetValueFromNormalizedMessage(lines, "Column="); int num2 = (valueFromNormalizedMessage == null) ? -1 : int.Parse(valueFromNormalizedMessage); string valueFromNormalizedMessage2 = APIUpdaterHelper.GetValueFromNormalizedMessage(lines, "Script="); Type result; if (num == -1 || num2 == -1 || valueFromNormalizedMessage2 == null) { result = null; } else { using (FileStream fileStream = File.Open(valueFromNormalizedMessage2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { IParser parser = ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.CSharp, new StreamReader(fileStream)); parser.Lexer.EvaluateConditionalCompilation = false; parser.Parse(); string text = InvalidTypeOrNamespaceErrorTypeMapper.IsTypeMovedToNamespaceError(parser.CompilationUnit, num, num2); if (text == null) { result = null; } else { result = APIUpdaterHelper.FindExactTypeMatchingMovedType(text); } } } return(result); }
// C# compiler does not emmit the full qualified type name when it fails to resolve a 'theorically', fully qualified type reference // for instance, if 'NSBar', a namespace gets renamed to 'NSBar2', a refernce to 'NSFoo.NSBar.TypeBaz' will emit an error // with only NSBar and NSFoo in the message. In this case we use NRefactory to dive in to the code, looking for type references // in the reported error line/column private static Type FindTypeMatchingMovedTypeBasedOnNamespaceFromError(IEnumerable <string> lines) { var value = GetValueFromNormalizedMessage(lines, "Line="); var line = (value != null) ? Int32.Parse(value) : -1; value = GetValueFromNormalizedMessage(lines, "Column="); var column = (value != null) ? Int32.Parse(value) : -1; var script = GetValueFromNormalizedMessage(lines, "Script="); if (line == -1 || column == -1 || script == null) { return(null); } try { using (var scriptStream = File.Open(script, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StreamReader(scriptStream)); parser.Lexer.EvaluateConditionalCompilation = false; parser.Parse(); var typeNotFound = InvalidTypeOrNamespaceErrorTypeMapper.IsTypeMovedToNamespaceError(parser.CompilationUnit, line, column); if (typeNotFound == null) { return(null); } return(FindExactTypeMatchingMovedType(typeNotFound)); } } catch (FileNotFoundException) { return(null); } }