@@ -14,6 +14,7 @@ namespace ICSharpCode.CodeConverter.Shared
1414{
1515 public class ProjectConversion < TLanguageConversion > where TLanguageConversion : ILanguageConversion , new ( )
1616 {
17+ private readonly string _solutionDir ;
1718 private readonly Compilation _sourceCompilation ;
1819 private readonly IEnumerable < SyntaxTree > _syntaxTreesToConvert ;
1920 private static readonly AdhocWorkspace AdhocWorkspace = new AdhocWorkspace ( ) ;
@@ -25,6 +26,7 @@ namespace ICSharpCode.CodeConverter.Shared
2526 private ProjectConversion ( Compilation sourceCompilation , string solutionDir )
2627 : this ( sourceCompilation , sourceCompilation . SyntaxTrees . Where ( t => t . FilePath . StartsWith ( solutionDir ) ) )
2728 {
29+ _solutionDir = solutionDir ;
2830 }
2931
3032 private ProjectConversion ( Compilation sourceCompilation , IEnumerable < SyntaxTree > syntaxTreesToConvert )
@@ -53,7 +55,8 @@ public static async Task<ConversionResult> ConvertSingle(Compilation compilation
5355
5456 var conversion = new ProjectConversion < TLanguageConversion > ( compilation , new [ ] { syntaxTree } ) ;
5557 var conversionResults = ConvertProject ( conversion ) . ToList ( ) ;
56- var codeResult = conversionResults . Single ( x => ! string . IsNullOrWhiteSpace ( x . ConvertedCode ) ) ;
58+ var codeResult = conversionResults . SingleOrDefault ( x => ! string . IsNullOrWhiteSpace ( x . ConvertedCode ) )
59+ ?? conversionResults . First ( ) ;
5760 codeResult . Exceptions = conversionResults . SelectMany ( x => x . Exceptions ) . ToArray ( ) ;
5861 return codeResult ;
5962 }
@@ -88,6 +91,9 @@ private Dictionary<string, SyntaxNode> Convert()
8891 {
8992 FirstPass ( ) ;
9093 var secondPassByFilePath = SecondPass ( ) ;
94+ #if DEBUG && false
95+ AddProjectWarnings ( ) ;
96+ #endif
9197 return secondPassByFilePath ;
9298 }
9399
@@ -103,13 +109,19 @@ private Dictionary<string, SyntaxNode> SecondPass()
103109 _errors . TryAdd ( treeFilePath , e . ToString ( ) ) ;
104110 }
105111 }
106- var nonFatalWarningsOrNull = _languageConversion . GetNonFatalWarningsOrNull ( ) ;
107- if ( ! string . IsNullOrWhiteSpace ( nonFatalWarningsOrNull ) ) {
108- _errors . TryAdd ( "" , nonFatalWarningsOrNull ) ;
109- }
110112 return secondPassByFilePath ;
111113 }
112114
115+ private void AddProjectWarnings ( )
116+ {
117+ var nonFatalWarningsOrNull = _languageConversion . GetWarningsOrNull ( ) ;
118+ if ( ! string . IsNullOrWhiteSpace ( nonFatalWarningsOrNull ) )
119+ {
120+ var warningsDescription = Path . Combine ( _solutionDir ?? "" , _sourceCompilation . AssemblyName , "ConversionWarnings.txt" ) ;
121+ _errors . TryAdd ( warningsDescription , nonFatalWarningsOrNull ) ;
122+ }
123+ }
124+
113125 private SyntaxNode SingleSecondPass ( KeyValuePair < string , SyntaxTree > cs )
114126 {
115127 var secondPassNode = _languageConversion . SingleSecondPass ( cs ) ;
0 commit comments