Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Microsoft.Toolkit/Diagnostics/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
#if NETSTANDARD1_4
using Microsoft.Toolkit.Extensions;
#endif

#nullable enable

Expand Down
33 changes: 32 additions & 1 deletion Microsoft.Toolkit/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
#if NETSTANDARD1_4
using System.Reflection;
#endif
using System.Runtime.CompilerServices;

#nullable enable
Expand Down Expand Up @@ -62,7 +65,12 @@ static string FormatDisplayString(Type type)
}

// Generic types
if (type.IsGenericType &&
if (
#if NETSTANDARD1_4
type.GetTypeInfo().IsGenericType &&
#else
type.IsGenericType &&
#endif
type.FullName is { } fullName &&
fullName.Split('`') is { } tokens &&
tokens.Length > 0 &&
Expand Down Expand Up @@ -113,5 +121,28 @@ tokens[0] is { } genericName &&
// be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835.
return DisplayNames.GetValue(type, t => FormatDisplayString(t));
}

#if NETSTANDARD1_4
/// <summary>
/// Returns an array of types representing the generic arguments.
/// </summary>
/// <param name="type">The input type.</param>
/// <returns>An array of types representing the generic arguments.</returns>
private static Type[] GetGenericArguments(this Type type)
{
return type.GetTypeInfo().GenericTypeParameters;
}

/// <summary>
/// Returns whether <paramref name="type"/> is an instance of <paramref name="value"/>.
/// </summary>
/// <param name="type">The input type.</param>
/// <param name="value">The type to check against.</param>
/// <returns><see langword="true"/> if <paramref name="type"/> is an instance of <paramref name="value"/>, <see langword="false"/> otherwise.</returns>
internal static bool IsInstanceOfType(this Type type, object value)
{
return type.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo());
}
#endif
}
}
11 changes: 9 additions & 2 deletions Microsoft.Toolkit/Microsoft.Toolkit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard1.4;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Title>Windows Community Toolkit .NET Standard</Title>
Expand All @@ -13,6 +13,13 @@
<PackageTags>UWP Toolkit Windows IncrementalLoadingCollection String Array extensions helpers</PackageTags>
</PropertyGroup>

<!-- .NET Standard 1.4 doesn't have the Span<T> type, ValueTuple or the [Pure] attribute -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.4" />
Expand Down Expand Up @@ -70,4 +77,4 @@
</Compile>
</ItemGroup>

</Project>
</Project>