Add ValueTask support (#89)

* Add ValueTask support

* remove netstandard2.1
This commit is contained in:
彭伟 2019-11-30 10:12:04 +08:00 committed by Ben Adams
parent c061f764bd
commit eaf0393860
3 changed files with 18 additions and 9 deletions

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Product>Ben Core</Product>
@ -15,16 +15,18 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<!--<TargetFrameworks>netstandard2.0;netstandard2.1;net45</TargetFrameworks>-->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="2.1.17" PrivateAssets="all" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.7.6" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.25" PrivateAssets="all" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="all" />
<PackageReference Include="System.Reflection.Metadata">
<Version>1.5.0</Version>
<Version>1.6.0</Version>
</PackageReference>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" Condition="'$(TargetFramework)' != 'netstandard2.1'" />
</ItemGroup>
<ItemGroup Label="TestInternalsVisibleTo">

View File

@ -51,7 +51,7 @@ namespace System.Diagnostics
{
var frame = stackFrames[i];
var method = frame.GetMethod();
// Always show last stackFrame
if (!ShowInStackTrace(method) && i < stackFrames.Length - 1)
{
@ -647,6 +647,10 @@ namespace System.Diagnostics
{
return false;
}
if (type == typeof(ValueTask<>) && method.Name == "get_Result")
{
return false;
}
if (type == typeof(Task))
{
switch (method.Name)
@ -687,6 +691,10 @@ namespace System.Diagnostics
}
else if (type == typeof(TaskAwaiter) ||
type == typeof(TaskAwaiter<>) ||
type == typeof(ValueTaskAwaiter) ||
type == typeof(ValueTaskAwaiter<>) ||
type == typeof(ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter) ||
type == typeof(ConfiguredValueTaskAwaitable<>.ConfiguredValueTaskAwaiter) ||
type == typeof(ConfiguredTaskAwaitable.ConfiguredTaskAwaiter) ||
type == typeof(ConfiguredTaskAwaitable<>.ConfiguredTaskAwaiter))
{

View File

@ -39,13 +39,12 @@ namespace Ben.Demystifier.Test
}
}
Exception GetMixedStackException()
{
Exception exception = null;
try
{
Start((val:"", true));
Start((val: "", true));
}
catch (Exception ex)
{
@ -61,7 +60,7 @@ namespace Ben.Demystifier.Test
"string string.Join(string separator, IEnumerable<string> values)",
"string Ben.Demystifier.Test.MixedStack+GenericClass<T>.GenericMethod<V>(ref V value)",
"async Task<string> Ben.Demystifier.Test.MixedStack.MethodAsync(int value)",
"async Task<string> Ben.Demystifier.Test.MixedStack.MethodAsync<TValue>(TValue value)",
"async ValueTask<string> Ben.Demystifier.Test.MixedStack.MethodAsync<TValue>(TValue value)",
"(string val, bool) Ben.Demystifier.Test.MixedStack.Method(string value)",
"ref string Ben.Demystifier.Test.MixedStack.RefMethod(string value)",
"(string val, bool) Ben.Demystifier.Test.MixedStack.s_func(string s, bool b)",
@ -91,7 +90,7 @@ namespace Ben.Demystifier.Test
}
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
static async Task<string> MethodAsync<TValue>(TValue value) => await MethodAsync(1);
static async ValueTask<string> MethodAsync<TValue>(TValue value) => await MethodAsync(1);
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
static (string val, bool) Method(string value) => (MethodAsync(value).GetAwaiter().GetResult(), true);