Skip to content

Commit 9d34d93

Browse files
committed
Fix build of projects that import code from Core.Design
Especially those targeting .NET Framework
1 parent c2dfe9e commit 9d34d93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+409
-5
lines changed

sources/assets/Stride.Core.Assets.Tests/Stride.Core.Assets.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
55
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<LangVersion>latest</LangVersion>
68
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
79
<StrideAssemblyProcessorOptions>--auto-module-initializer --serialization</StrideAssemblyProcessorOptions>
810
</PropertyGroup>

sources/core/Stride.Core.CompilerServices.Tests/Stride.Core.CompilerServices.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="..\..\targets\Stride.UnitTests.props" />
33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>$(StrideXplatEditorTargetFramework)</TargetFramework>
55
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
66
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
77
<StrideAssemblyProcessorOptions>--auto-module-initializer</StrideAssemblyProcessorOptions>

sources/core/Stride.Core.Design.Tests/Stride.Core.Design.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
55
<StrideAssemblyProcessorOptions>--auto-module-initializer --serialization</StrideAssemblyProcessorOptions>
6-
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
6+
<TargetFramework>$(StrideXplatEditorTargetFramework)</TargetFramework>
77
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<LangVersion>latest</LangVersion>

sources/core/Stride.Core.Design/Collections/HybridDictionary.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public HybridDictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary,
4444

4545
public HybridDictionary(int capacity, IEqualityComparer<TKey>? comparer)
4646
{
47+
#if NET8_0_OR_GREATER
4748
ArgumentOutOfRangeException.ThrowIfNegative(capacity);
49+
#else
50+
if (capacity <= 0) throw new ArgumentOutOfRangeException(nameof(capacity))
51+
#endif
4852
keyComparer = comparer ?? EqualityComparer<TKey>.Default;
4953
if (capacity >= ConstructorCutoverPoint)
5054
{
@@ -189,7 +193,11 @@ public void Clear()
189193
public bool Contains(KeyValuePair<TKey, TValue> item)
190194
{
191195
CheckInvariant();
196+
#if NET6_0_OR_GREATER
192197
ArgumentNullException.ThrowIfNull(item.Key);
198+
#else
199+
if (item.Key is null) throw new ArgumentNullException(nameof(item.Key));
200+
#endif
193201
if (list != null)
194202
{
195203
foreach (var kvp in list)
@@ -218,7 +226,11 @@ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
218226
public bool ContainsKey(TKey key)
219227
{
220228
CheckInvariant();
229+
#if NET6_0_OR_GREATER
221230
ArgumentNullException.ThrowIfNull(key);
231+
#else
232+
if (key is null) throw new ArgumentNullException(nameof(key));
233+
#endif
222234
if (list != null)
223235
{
224236
foreach (var kvp in list)
@@ -234,7 +246,11 @@ public bool ContainsKey(TKey key)
234246
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
235247
{
236248
CheckInvariant();
249+
#if NET6_0_OR_GREATER
237250
ArgumentNullException.ThrowIfNull(key);
251+
#else
252+
if (key is null) throw new ArgumentNullException(nameof(key));
253+
#endif
238254
if (list != null)
239255
{
240256
foreach (var kvp in list)

sources/core/Stride.Core.Design/Extensions/AnonymousEqualityComparer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ public class AnonymousEqualityComparer<T> : IEqualityComparer<T>
1919
/// <param name="getHashCode">The function to use to compute hash codes for the objects to compare.</param>
2020
public AnonymousEqualityComparer(Func<T?, T?, bool> equals, Func<T, int> getHashCode)
2121
{
22+
#if NET6_0_OR_GREATER
2223
ArgumentNullException.ThrowIfNull(equals);
2324
ArgumentNullException.ThrowIfNull(getHashCode);
25+
#else
26+
if (equals is null) throw new ArgumentNullException(nameof(equals));
27+
if (getHashCode is null) throw new ArgumentNullException(nameof(getHashCode));
28+
#endif
2429
this.equals = equals;
2530
this.getHashCode = getHashCode;
2631
}

sources/core/Stride.Core.Design/Extensions/DesignExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public static class DesignExtensions
1919
[Pure]
2020
public static bool IsReadOnly([NoEnumeration] this IEnumerable source)
2121
{
22+
#if NET6_0_OR_GREATER
2223
ArgumentNullException.ThrowIfNull(source);
24+
#else
25+
if (source is null) throw new ArgumentNullException(nameof(source));
26+
#endif
2327

2428
if (source is ICollection<object> collection)
2529
return collection.IsReadOnly;
@@ -59,8 +63,13 @@ public static IEnumerable<T> Enumerate<T>(this IEnumerator enumerator)
5963
[Pure]
6064
public static IEnumerable<Tuple<T1, T2>> Zip<T1, T2>(this IEnumerable<T1> enumerable1, IEnumerable<T2> enumerable2)
6165
{
66+
#if NET6_0_OR_GREATER
6267
ArgumentNullException.ThrowIfNull(enumerable1);
6368
ArgumentNullException.ThrowIfNull(enumerable2);
69+
#else
70+
if (enumerable1 is null) throw new ArgumentNullException(nameof(enumerable1));
71+
if (enumerable2 is null) throw new ArgumentNullException(nameof(enumerable2));
72+
#endif
6473

6574
return Impl();
6675

@@ -94,7 +103,11 @@ IEnumerable<Tuple<T1, T2>> Impl()
94103
[Pure]
95104
public static IEnumerable<T> SelectDeep<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> childrenSelector)
96105
{
106+
#if NET6_0_OR_GREATER
97107
ArgumentNullException.ThrowIfNull(childrenSelector);
108+
#else
109+
if (childrenSelector is null) throw new ArgumentNullException(nameof(childrenSelector));
110+
#endif
98111

99112
return Impl();
100113

@@ -127,7 +140,11 @@ IEnumerable<T> Impl()
127140
[Pure]
128141
public static IEnumerable<T> BreadthFirst<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> childrenSelector)
129142
{
143+
#if NET6_0_OR_GREATER
130144
ArgumentNullException.ThrowIfNull(childrenSelector);
145+
#else
146+
if (childrenSelector is null) throw new ArgumentNullException(nameof(childrenSelector));
147+
#endif
131148

132149
return Impl();
133150

@@ -161,8 +178,13 @@ IEnumerable<T> Impl()
161178
[Pure]
162179
public static IEnumerable<T> DepthFirst<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> childrenSelector)
163180
{
181+
#if NET6_0_OR_GREATER
164182
ArgumentNullException.ThrowIfNull(source);
165183
ArgumentNullException.ThrowIfNull(childrenSelector);
184+
#else
185+
if (source is null) throw new ArgumentNullException(nameof(source));
186+
if (childrenSelector is null) throw new ArgumentNullException(nameof(childrenSelector));
187+
#endif
166188

167189
return Impl();
168190

@@ -297,7 +319,11 @@ public static TValue GetOrCreateValue<TKey, TValue>(this IDictionary<TKey, TValu
297319
/// <returns>The value attached to key, if key already exists in the dictionary; otherwise, the new value returned by the <paramref name="createValueFunc"/>.</returns>
298320
public static TValue GetOrCreateValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> createValueFunc)
299321
{
322+
#if NET6_0_OR_GREATER
300323
ArgumentNullException.ThrowIfNull(dictionary);
324+
#else
325+
if (dictionary is null) throw new ArgumentNullException(nameof(dictionary));
326+
#endif
301327
if (!dictionary.TryGetValue(key, out var value))
302328
{
303329
value = createValueFunc.Invoke(key);

sources/core/Stride.Core.Design/Extensions/ObjectExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public static string ToStringSafe([CanBeNull] this object obj)
7070
[NotNull]
7171
public static T SafeArgument<T>(this T obj, [CallerArgumentExpression(nameof(obj))] string argumentName = "") where T : class
7272
{
73+
#if NET6_0_OR_GREATER
7374
ArgumentNullException.ThrowIfNull(argumentName);
75+
#else
76+
if (argumentName is null) throw new ArgumentNullException(nameof(argumentName));
77+
#endif
7478
if (obj == null) throw new ArgumentNullException(argumentName);
7579
return obj;
7680
}

sources/core/Stride.Core.Design/Extensions/TaskExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public static class TaskExtensions
1010
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1111
public static void Forget(this Task task)
1212
{
13+
#if NET6_0_OR_GREATER
1314
ArgumentNullException.ThrowIfNull(task);
15+
#else
16+
if (task is null) throw new ArgumentNullException(nameof(task));
17+
#endif
1418
}
1519
}

sources/core/Stride.Core.Design/IO/UDirectory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public static UDirectory Combine(UDirectory leftPath, UDirectory rightPath)
8484
/// <returns><c>true</c> if this directory contains the specified path; otherwise, <c>false</c>.</returns>
8585
public bool Contains(UPath path)
8686
{
87+
#if NET6_0_OR_GREATER
8788
ArgumentNullException.ThrowIfNull(path);
89+
#else
90+
if (path is null) throw new ArgumentNullException(nameof(path));
91+
#endif
8892
return path.FullPath.StartsWith(FullPath, StringComparison.OrdinalIgnoreCase) && path.FullPath.Length > FullPath.Length && path.FullPath[FullPath.Length] == DirectorySeparatorChar;
8993
}
9094
}

sources/core/Stride.Core.Design/IO/UFile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public static UFile Combine(UDirectory leftPath, UFile rightPath)
128128
/// <returns><c>true</c> if the specified path is a valid <see cref="UFile"/>; otherwise, <c>false</c>.</returns>
129129
public static new bool IsValid(string path)
130130
{
131+
#if NET6_0_OR_GREATER
131132
ArgumentNullException.ThrowIfNull(path);
133+
#else
134+
if (path is null) throw new ArgumentNullException(nameof(path));
135+
#endif
132136
if (!UPath.IsValid(path))
133137
{
134138
return false;

0 commit comments

Comments
 (0)