mirror of https://github.com/icsharpcode/ILSpy.git
4 changed files with 175 additions and 0 deletions
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using System.IO; |
||||
|
||||
namespace EquivalentCSharpConsoleApp |
||||
{ |
||||
static class Program |
||||
{ |
||||
public static void Main(string[] args) |
||||
{ |
||||
var task = new Task(ProcessDataAsync); |
||||
task.Start(); |
||||
task.Wait(); |
||||
Console.ReadLine(); |
||||
} |
||||
|
||||
public async static void ProcessDataAsync() |
||||
{ |
||||
Task<int> task = HandleFileAsync("C:\\enable1.txt"); |
||||
Console.WriteLine("Please wait, processing"); |
||||
int result = await task; |
||||
Console.WriteLine("Count: " + result.ToString()); |
||||
} |
||||
|
||||
public async static Task<int> HandleFileAsync(string file) |
||||
{ |
||||
Console.WriteLine("HandleFile enter"); |
||||
int count = 0; |
||||
using (StreamReader reader = new StreamReader(file)) |
||||
{ |
||||
string value = await reader.ReadToEndAsync(); |
||||
count += value.Length; |
||||
for (var i = 0; i <= 10000; i += 1) |
||||
{ |
||||
var x = value.GetHashCode(); |
||||
if (x == 0) |
||||
count -= 1; |
||||
} |
||||
} |
||||
|
||||
Console.WriteLine("HandleFile exit"); |
||||
return count; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
Imports System |
||||
Imports System.IO |
||||
|
||||
Module Program |
||||
' Sample taken verbatim from https://www.dotnetperls.com/async-vbnet |
||||
Sub Main(args As String()) |
||||
Dim task = New Task(AddressOf ProcessDataAsync) |
||||
' Start and wait for task to end. |
||||
task.Start() |
||||
task.Wait() |
||||
Console.ReadLine() |
||||
End Sub |
||||
|
||||
Async Sub ProcessDataAsync() |
||||
' Create a task Of Integer. |
||||
' ... Use HandleFileAsync method with a large file. |
||||
Dim task As Task(Of Integer) = HandleFileAsync("C:\enable1.txt") |
||||
' This statement runs while HandleFileAsync executes. |
||||
Console.WriteLine("Please wait, processing") |
||||
' Use await to wait for task to complete. |
||||
Dim result As Integer = Await task |
||||
Console.WriteLine("Count: " + result.ToString()) |
||||
End Sub |
||||
|
||||
Async Function HandleFileAsync(ByVal file As String) As Task(Of Integer) |
||||
Console.WriteLine("HandleFile enter") |
||||
|
||||
' Open the file. |
||||
Dim count As Integer = 0 |
||||
Using reader As StreamReader = New StreamReader(file) |
||||
Dim value As String = Await reader.ReadToEndAsync() |
||||
count += value.Length |
||||
|
||||
' Do a slow computation on the file. |
||||
For i = 0 To 10000 Step 1 |
||||
Dim x = value.GetHashCode() |
||||
If x = 0 Then |
||||
count -= 1 |
||||
End If |
||||
|
||||
Next |
||||
End Using |
||||
|
||||
Console.WriteLine("HandleFile exit") |
||||
Return count |
||||
End Function |
||||
End Module |
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Runtime.CompilerServices; |
||||
using ICSharpCode.Decompiler.Tests.Helpers; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests |
||||
{ |
||||
[TestFixture, Parallelizable(ParallelScope.All)] |
||||
public class VBPrettyTestRunner |
||||
{ |
||||
static readonly string TestCasePath = DecompilerTestBase.TestCasePath + "/ILPretty"; |
||||
|
||||
[Test] |
||||
public void AllFilesHaveTests() |
||||
{ |
||||
var testNames = typeof(ILPrettyTestRunner).GetMethods() |
||||
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any()) |
||||
.Select(m => m.Name) |
||||
.ToArray(); |
||||
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) { |
||||
if (file.Extension.Equals(".vb", StringComparison.OrdinalIgnoreCase)) { |
||||
var testName = file.Name.Split('.')[0]; |
||||
Assert.Contains(testName, testNames); |
||||
Assert.IsTrue(File.Exists(Path.Combine(TestCasePath, testName + ".cs"))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static readonly VBCompilerOptions[] defaultOptions = |
||||
{ |
||||
VBCompilerOptions.None, |
||||
VBCompilerOptions.Optimize, |
||||
VBCompilerOptions.UseRoslyn, |
||||
VBCompilerOptions.Optimize | VBCompilerOptions.UseRoslyn, |
||||
}; |
||||
|
||||
static readonly VBCompilerOptions[] roslynOnlyOptions = |
||||
{ |
||||
VBCompilerOptions.UseRoslyn, |
||||
VBCompilerOptions.Optimize | VBCompilerOptions.UseRoslyn, |
||||
}; |
||||
|
||||
[Test, Ignore("Implement VB async/await")] |
||||
public void Async([ValueSource("defaultOptions")] VBCompilerOptions options) |
||||
{ |
||||
Run(options: options); |
||||
} |
||||
|
||||
void Run([CallerMemberName] string testName = null, VBCompilerOptions options = VBCompilerOptions.UseDebug, DecompilerSettings settings = null) |
||||
{ |
||||
var vbFile = Path.Combine(TestCasePath, testName + ".vb"); |
||||
var csFile = Path.Combine(TestCasePath, testName + ".cs"); |
||||
|
||||
var executable = Tester.CompileVB(vbFile, options); |
||||
var decompiled = Tester.DecompileCSharp(executable.PathToAssembly, settings); |
||||
|
||||
CodeAssert.FilesAreEqual(csFile, decompiled); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue