Skip to content

Commit 4135748

Browse files
committed
Added net9.0 netstandard2.x support.
1 parent e431d71 commit 4135748

36 files changed

+522
-92
lines changed

AndroidTests/AndroidTests.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0-android</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

Hexa.NET.ImGui.Widgets.Extras/Hexa.NET.ImGui.Widgets.Extras.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<PackageReference Include="Hexa.NET.Math" Version="2.0.2" />
41+
<PackageReference Include="Hexa.NET.Math" Version="2.0.3" />
4242
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
4343
</ItemGroup>
4444

Hexa.NET.ImGui.Widgets.Tests/Hexa.NET.ImGui.Widgets.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16-
<PackageReference Include="NUnit" Version="3.14.0" />
17-
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
18-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
14+
<PackageReference Include="coverlet.collector" Version="6.0.2" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
16+
<PackageReference Include="NUnit" Version="4.2.2" />
17+
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

Hexa.NET.ImGui.Widgets/ComboHelper.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Hexa.NET.ImGui;
44
using System;
5+
using System.Linq;
56
using System.Diagnostics.CodeAnalysis;
67

78
/// <summary>
@@ -10,8 +11,13 @@
1011
/// <typeparam name="T">The enum type.</typeparam>
1112
public static class ComboEnumHelper<T> where T : struct, Enum
1213
{
14+
#if NET5_0_OR_GREATER
1315
private static readonly T[] values = Enum.GetValues<T>();
1416
private static readonly string[] names = Enum.GetNames<T>();
17+
#else
18+
private static readonly T[] values = (T[])Enum.GetValues(typeof(T));
19+
private static readonly string[] names = Enum.GetNames(typeof(T));
20+
#endif
1521

1622
/// <summary>
1723
/// Displays a combo box to select an enum value.
@@ -54,9 +60,15 @@ public static class ComboEnumHelper
5460
{
5561
private static readonly Dictionary<Type, object[]> values = new();
5662
private static readonly Dictionary<Type, string[]> names = new();
63+
#if NET7_0_OR_GREATER
5764

5865
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "All members are included by [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)].")]
59-
private static void Get([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, out object[] values, out string[] names)
66+
#endif
67+
private static void Get(
68+
#if NET7_0_OR_GREATER
69+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
70+
#endif
71+
Type type, out object[] values, out string[] names)
6072
{
6173
if (ComboEnumHelper.values.TryGetValue(type, out var objects))
6274
{
@@ -78,7 +90,11 @@ private static void Get([DynamicallyAccessedMembers(DynamicallyAccessedMemberTyp
7890
/// <param name="type">The enum type to select values from.</param>
7991
/// <param name="value">The currently selected enum value (modified by user interaction).</param>
8092
/// <returns><c>true</c> if the user selects a new value, <c>false</c> otherwise.</returns>
81-
public static bool Combo(string label, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, ref object value)
93+
public static bool Combo(string label,
94+
#if NET7_0_OR_GREATER
95+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
96+
#endif
97+
Type type, ref object value)
8298
{
8399
Get(type, out var values, out var names);
84100
int index = Array.IndexOf(values, value);
@@ -95,7 +111,11 @@ public static bool Combo(string label, [DynamicallyAccessedMembers(DynamicallyAc
95111
/// </summary>
96112
/// <param name="type">The enum type to select values from.</param>
97113
/// <param name="value">The enum value to display.</param>
98-
public static void Text([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object value)
114+
public static void Text(
115+
#if NET7_0_OR_GREATER
116+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
117+
#endif
118+
Type type, object value)
99119
{
100120
Get(type, out var values, out var names);
101121
int index = Array.IndexOf(values, value);

Hexa.NET.ImGui.Widgets/Dialogs/CompareByDateModifiedComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
public int Compare(T a, T b)
66
{
7-
int cmp = IFileSystemItem.CompareByBase(a, b);
7+
int cmp = BaseComparer.CompareByBase(a, b);
88
if (cmp != 0)
99
{
1010
return cmp;

Hexa.NET.ImGui.Widgets/Dialogs/CompareByNameComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
public int Compare(T a, T b)
66
{
7-
int cmp = IFileSystemItem.CompareByBase(a, b);
7+
int cmp = BaseComparer.CompareByBase(a, b);
88
if (cmp != 0)
99
{
1010
return cmp;

Hexa.NET.ImGui.Widgets/Dialogs/CompareBySizeComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
public int Compare(T a, T b)
66
{
7-
int cmp = IFileSystemItem.CompareByBase(a, b);
7+
int cmp = BaseComparer.CompareByBase(a, b);
88
if (cmp != 0)
99
{
1010
return cmp;

Hexa.NET.ImGui.Widgets/Dialogs/CompareByTypeComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
public int Compare(T a, T b)
66
{
7-
int cmp = IFileSystemItem.CompareByBase(a, b);
7+
int cmp = BaseComparer.CompareByBase(a, b);
88
if (cmp != 0)
99
{
1010
return cmp;

Hexa.NET.ImGui.Widgets/Dialogs/DialogManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@ public static void Draw()
4545
ImGui.EndDisabled();
4646
}
4747

48+
#if NETSTANDARD2_0
49+
50+
while (closing.Count > 0)
51+
{
52+
var dialog = closing.Dequeue();
53+
dialogs.Remove(dialog);
54+
}
55+
#else
4856
while (closing.TryDequeue(out var dialog))
4957
{
5058
dialogs.Remove(dialog);
5159
}
60+
#endif
5261

5362
WidgetManager.BlockInput = dialogs.Count > 0;
5463
}

Hexa.NET.ImGui.Widgets/Dialogs/FileDialogBase.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Hexa.NET.ImGui;
44
using Hexa.NET.ImGui.Widgets;
5+
using Hexa.NET.ImGui.Widgets.Extensions;
56
using Hexa.NET.ImGui.Widgets.IO;
67
using Hexa.NET.ImGui.Widgets.Text;
78
using System.Diagnostics;
@@ -610,20 +611,40 @@ public virtual void GoHome()
610611

611612
public virtual void TryGoBack()
612613
{
614+
#if NETSTANDARD2_0
615+
616+
if (backHistory.Count > 0)
617+
{
618+
var historyItem = backHistory.Pop();
619+
forwardHistory.Push(CurrentFolder);
620+
SetInternal(historyItem);
621+
}
622+
#else
613623
if (backHistory.TryPop(out var historyItem))
614624
{
615625
forwardHistory.Push(CurrentFolder);
616626
SetInternal(historyItem);
617627
}
628+
#endif
618629
}
619630

620631
public virtual void TryGoForward()
621632
{
633+
#if NETSTANDARD2_0
634+
635+
if (forwardHistory.Count > 0)
636+
{
637+
var historyItem = forwardHistory.Pop();
638+
backHistory.Push(CurrentFolder);
639+
SetInternal(historyItem);
640+
}
641+
#else
622642
if (forwardHistory.TryPop(out var historyItem))
623643
{
624644
backHistory.Push(CurrentFolder);
625645
SetInternal(historyItem);
626646
}
647+
#endif
627648
}
628649

629650
public void ClearHistory()
@@ -733,7 +754,7 @@ protected virtual bool FileSystemItemSearchFilter(FileSystemItem arg)
733754

734755
protected virtual string IconSelector(FileMetadata file)
735756
{
736-
ReadOnlySpan<char> extension = Path.GetExtension(file.Path.AsSpan());
757+
ReadOnlySpan<char> extension = FileUtils.GetExtension(file.Path.AsSpan());
737758

738759
switch (extension)
739760
{

Hexa.NET.ImGui.Widgets/Dialogs/FileSystemHelper.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void ClearCache()
9595
foreach (var drive in DriveInfo.GetDrives())
9696
{
9797
// shouldn't be a performance concern, but if it ever gets to the point use a trie.
98-
if (drive.Name.StartsWith('/') && ignoredDrives.Any(x => drive.Name.AsSpan(1).StartsWith(x)))
98+
if (drive.Name.StartsWith('/') && ignoredDrives.Any(x => drive.Name.AsSpan(1).StartsWith(x.AsSpan())))
9999
{
100100
continue;
101101
}
@@ -231,20 +231,23 @@ public static IEnumerable<FileSystemItem> Refresh(string folder, RefreshFlags re
231231
continue;
232232

233233
var span = metadata.Path.AsSpan();
234-
var name = Path.GetFileName(span);
234+
var name = FileUtils.GetFileName(span);
235235

236236
if (searchOptions.Filter(metadata))
237237
{
238238
if (onlyAllowFilteredExtensions && !isDir)
239239
{
240-
var ext = Path.GetExtension(name);
240+
var ext = FileUtils.GetExtension(name);
241241
if (!allowedExtensions!.Contains(ext, comparison))
242242
{
243243
continue;
244244
}
245245
}
246-
246+
#if NET5_0_OR_GREATER
247247
var itemName = option == SearchOption.AllDirectories ? $"{name}##{id++}" : name.ToString();
248+
#else
249+
var itemName = option == SearchOption.AllDirectories ? $"{name.ToString()}##{id++}" : name.ToString();
250+
#endif
248251
var decorator = isDir ? $"{folderDecorator}" : fileDecorator(metadata);
249252
FileSystemItem item = new(metadata, itemName, decorator, isDir ? FileSystemItemFlags.Folder : FileSystemItemFlags.None);
250253
yield return item;
@@ -285,7 +288,7 @@ public static List<FileSystemItem> GetFileSystemEntries(string folder, RefreshFl
285288
continue;
286289

287290
var span = metadata.Path.AsSpan();
288-
var name = Path.GetFileName(span);
291+
var name = FileUtils.GetFileName(span);
289292

290293
var itemName = name.ToString();
291294

@@ -302,7 +305,7 @@ public static List<FileSystemItem> GetFileSystemEntries(string folder, RefreshFl
302305
{
303306
if (onlyAllowFilteredExtensions)
304307
{
305-
var ext = Path.GetExtension(span);
308+
var ext = FileUtils.GetExtension(span);
306309
if (allowedExtensions!.Contains(ext, StringComparison.OrdinalIgnoreCase))
307310
{
308311
items.Add(new FileSystemItem(metadata, itemName, string.Empty, FileSystemItemFlags.None));

Hexa.NET.ImGui.Widgets/Dialogs/FileSystemItem.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public FileSystemItem(string path, string icon, string name, FileSystemItemFlags
3131
if (IsFile)
3232
{
3333
size = path.TryReturn(FileUtils.GetFileSize);
34-
type = DetermineFileType(System.IO.Path.GetExtension(path.AsSpan()));
34+
type = DetermineFileType(FileUtils.GetExtension(path.AsSpan()));
3535
}
3636
else
3737
{
@@ -50,7 +50,7 @@ public FileSystemItem(FileMetadata metadata, string name, string icon, FileSyste
5050
if (IsFile)
5151
{
5252
size = metadata.Size;
53-
type = DetermineFileType(System.IO.Path.GetExtension(path.AsSpan()));
53+
type = DetermineFileType(FileUtils.GetExtension(path.AsSpan()));
5454
}
5555
else
5656
{
@@ -69,14 +69,16 @@ public FileSystemItem(string path, string icon, FileSystemItemFlags flags)
6969
if (IsFile)
7070
{
7171
size = path.TryReturn(FileUtils.GetFileSize);
72-
type = DetermineFileType(System.IO.Path.GetExtension(path.AsSpan()));
72+
type = DetermineFileType(FileUtils.GetExtension(path.AsSpan()));
7373
}
7474
else
7575
{
7676
type = "File Folder";
7777
}
7878
}
7979

80+
#if NET5_0_OR_GREATER
81+
8082
private static CommonFilePermissions ConvertUnixPermissions(UnixFileMode permissions)
8183
{
8284
CommonFilePermissions result = CommonFilePermissions.None;
@@ -154,6 +156,8 @@ private static CommonFilePermissions ConvertWindowsPermissions(FileSecurity secu
154156
return result;
155157
}
156158

159+
#endif
160+
157161
public readonly bool IsFile => (flags & FileSystemItemFlags.Folder) == 0;
158162

159163
public readonly bool IsFolder => (flags & FileSystemItemFlags.Folder) != 0;
@@ -195,7 +199,11 @@ public static string DetermineFileType(ReadOnlySpan<char> extension)
195199
return type;
196200
}
197201

202+
#if NET5_0_OR_GREATER
198203
type = $"{extension} File"; // generic type name
204+
#else
205+
type = $"{extension.ToString()} File"; // generic type name
206+
#endif
199207
fileTypes.TryAdd(hash, type);
200208

201209
return type;

Hexa.NET.ImGui.Widgets/Dialogs/IFileSystemItem.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,25 @@ public interface IFileSystemItem
1818

1919
CommonFilePermissions Permissions { get; }
2020

21+
#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
22+
2123
public bool IsFile => (Flags & FileSystemItemFlags.Folder) == 0;
2224

2325
public bool IsFolder => (Flags & FileSystemItemFlags.Folder) != 0;
2426

2527
public bool IsHidden => (Flags & FileSystemItemFlags.Hidden) != 0;
2628

29+
#else
30+
public bool IsFile { get; }
31+
32+
public bool IsFolder { get; }
33+
34+
public bool IsHidden { get; }
35+
#endif
36+
}
37+
38+
public static class BaseComparer
39+
{
2740
public static int CompareByBase(IFileSystemItem a, IFileSystemItem b)
2841
{
2942
if (a.IsFolder && !b.IsFolder)

0 commit comments

Comments
 (0)