|
10 | 10 | using System.Windows; |
11 | 11 | using CommunityToolkit.Mvvm.ComponentModel; |
12 | 12 | using CommunityToolkit.Mvvm.Input; |
| 13 | +using ControlzEx.Standard; |
13 | 14 | using ICSharpCode.AvalonEdit.Document; |
14 | 15 | using ICSharpCode.AvalonEdit.Highlighting; |
15 | 16 | using Microsoft.CodeAnalysis; |
@@ -88,6 +89,20 @@ private void ContinueAction() |
88 | 89 | .WithUsings( |
89 | 90 | SyntaxFactory.List<UsingDirectiveSyntax>( |
90 | 91 | new UsingDirectiveSyntax[]{ |
| 92 | + SyntaxFactory.UsingDirective( |
| 93 | + SyntaxFactory.IdentifierName("System")) |
| 94 | + .WithUsingKeyword( |
| 95 | + SyntaxFactory.Token( |
| 96 | + SyntaxFactory.TriviaList(), |
| 97 | + SyntaxKind.UsingKeyword, |
| 98 | + SyntaxFactory.TriviaList( |
| 99 | + SyntaxFactory.Space))) |
| 100 | + .WithSemicolonToken( |
| 101 | + SyntaxFactory.Token( |
| 102 | + SyntaxFactory.TriviaList(), |
| 103 | + SyntaxKind.SemicolonToken, |
| 104 | + SyntaxFactory.TriviaList( |
| 105 | + SyntaxFactory.CarriageReturnLineFeed))), |
91 | 106 | SyntaxFactory.UsingDirective( |
92 | 107 | SyntaxFactory.QualifiedName( |
93 | 108 | SyntaxFactory.IdentifierName("Microsoft"), |
@@ -264,39 +279,46 @@ private void ContinueAction() |
264 | 279 |
|
265 | 280 |
|
266 | 281 | var stream = CompilationUtilitys.CompileClientProxy(new List<SyntaxTree>() { treeFrame }); |
267 | | - |
268 | | - using (stream) |
| 282 | + if (stream!=null) |
269 | 283 | { |
270 | | - var assembly = Assembly.Load(stream.ToArray()); |
271 | | - _generatedServiceProxyAssembly = assembly; |
| 284 | + using (stream) |
| 285 | + { |
| 286 | + var assembly = Assembly.Load(stream.ToArray()); |
| 287 | + _generatedServiceProxyAssembly = assembly; |
272 | 288 |
|
273 | | - } |
274 | | - var serviceProxyTypes = _generatedServiceProxyAssembly.GetExportedTypes(); |
| 289 | + } |
| 290 | + var serviceProxyTypes = _generatedServiceProxyAssembly.GetExportedTypes(); |
275 | 291 |
|
276 | | - object serviceProxyObject = null; |
277 | | - Type serviceProxyObjectType = null; |
| 292 | + object serviceProxyObject = null; |
| 293 | + Type serviceProxyObjectType = null; |
278 | 294 |
|
279 | | - foreach (var serviceProxyType in serviceProxyTypes) |
280 | | - { |
281 | | - var typeInfo = serviceProxyType.GetTypeInfo(); |
282 | | - if (typeInfo.FullName=="RoslynSyntaxTool.Process.ProxyTreeGen") |
| 295 | + foreach (var serviceProxyType in serviceProxyTypes) |
283 | 296 | { |
284 | | - serviceProxyObjectType=serviceProxyType; |
285 | | - var instance = serviceProxyType.GetTypeInfo().GetConstructors().First().Invoke(null); |
286 | | - serviceProxyObject=instance; |
287 | | - } |
| 297 | + var typeInfo = serviceProxyType.GetTypeInfo(); |
| 298 | + if (typeInfo.FullName=="RoslynSyntaxTool.Process.ProxyTreeGen") |
| 299 | + { |
| 300 | + serviceProxyObjectType=serviceProxyType; |
| 301 | + var instance = serviceProxyType.GetTypeInfo().GetConstructors().First().Invoke(null); |
| 302 | + serviceProxyObject=instance; |
| 303 | + } |
288 | 304 |
|
289 | 305 |
|
290 | 306 |
|
| 307 | + } |
| 308 | + var result = "没有结果,请检查输入代码"; |
| 309 | + var processor = serviceProxyObjectType.GetMethod("Process"); |
| 310 | + if (processor!=null) |
| 311 | + { |
| 312 | + result = processor.Invoke(serviceProxyObject, null).ToString(); |
| 313 | + } |
| 314 | + |
| 315 | + responseText =result; |
291 | 316 | } |
292 | | - var result = "没有结果,请检查输入代码"; |
293 | | - var processor = serviceProxyObjectType.GetMethod("Process"); |
294 | | - if (processor!=null) |
| 317 | + else |
295 | 318 | { |
296 | | - result = processor.Invoke(serviceProxyObject, null).ToString(); |
297 | | - } |
| 319 | + responseText ="语法树动态编译出错,检查 EmitResult.Diagnostics 属性。请将源码和报错信息反馈至开发者,谢谢"; |
298 | 320 |
|
299 | | - responseText =result; |
| 321 | + } |
300 | 322 | } |
301 | 323 | catch (Exception ex) |
302 | 324 | { |
|
0 commit comments