Skip to content

Commit 8b29a06

Browse files
committed
Add .net standard 1.4 target to Microsoft.Toolkit project.
1 parent 5004edb commit 8b29a06

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

Microsoft.Toolkit/Diagnostics/Guard.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.Diagnostics;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Runtime.CompilerServices;
9+
#if NETSTANDARD1_4
10+
using Microsoft.Toolkit.Extensions;
11+
#endif
912

1013
#nullable enable
1114

Microsoft.Toolkit/Extensions/TypeExtensions.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.Collections.Generic;
77
using System.Diagnostics.Contracts;
88
using System.Linq;
9+
#if NETSTANDARD1_4
10+
using System.Reflection;
11+
#endif
912
using System.Runtime.CompilerServices;
1013

1114
#nullable enable
@@ -62,7 +65,12 @@ static string FormatDisplayString(Type type)
6265
}
6366

6467
// Generic types
65-
if (type.IsGenericType &&
68+
if (
69+
#if NETSTANDARD1_4
70+
type.GetTypeInfo().IsGenericType &&
71+
#else
72+
type.IsGenericType &&
73+
#endif
6674
type.FullName is { } fullName &&
6775
fullName.Split('`') is { } tokens &&
6876
tokens.Length > 0 &&
@@ -113,5 +121,28 @@ tokens[0] is { } genericName &&
113121
// be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835.
114122
return DisplayNames.GetValue(type, t => FormatDisplayString(t));
115123
}
124+
125+
#if NETSTANDARD1_4
126+
/// <summary>
127+
/// Returns an array of types representing the generic arguments.
128+
/// </summary>
129+
/// <param name="type">The input type.</param>
130+
/// <returns>An array of types representing the generic arguments.</returns>
131+
public static Type[] GetGenericArguments(this Type type)
132+
{
133+
return type.GetTypeInfo().GenericTypeParameters;
134+
}
135+
136+
/// <summary>
137+
/// Returns whether <paramref name="type"/> is an instance of <paramref name="value"/>.
138+
/// </summary>
139+
/// <param name="type">The input type.</param>
140+
/// <param name="value">The type to check against.</param>
141+
/// <returns>True if it is <paramref name="type"/> is an instance of <paramref name="value"/> false if not.</returns>
142+
public static bool IsInstanceOfType(this Type type, object value)
143+
{
144+
return type.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo());
145+
}
146+
#endif
116147
}
117148
}

Microsoft.Toolkit/Microsoft.Toolkit.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
4+
<TargetFrameworks>netstandard1.4;netstandard2.0;netstandard2.1</TargetFrameworks>
55
<LangVersion>8.0</LangVersion>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<Title>Windows Community Toolkit .NET Standard</Title>
@@ -16,6 +16,13 @@
1616
<DebugType>Full</DebugType>
1717
</PropertyGroup>
1818

19+
<!-- .NET Standard 1.4 doesn't have the Span<T> type, ValueTuple or System.Diagnostics.Contracts-->
20+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.4' ">
21+
<PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
22+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
23+
<PackageReference Include="System.Memory" Version="4.5.4" />
24+
</ItemGroup>
25+
1926
<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
2027
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
2128
<PackageReference Include="System.Memory" Version="4.5.4" />

0 commit comments

Comments
 (0)