Skip to content

Commit e2bc5bb

Browse files
support .net 4.7.2
support .net 4.7.2 support .net 4.7.2 tidy up. remove empty lines
1 parent 1a3f1a1 commit e2bc5bb

File tree

9 files changed

+219
-15
lines changed

9 files changed

+219
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ DeftSharp.Windows.Input.sln.DotSettings.user
77
WPF.Playground/bin
88
WPF.Playground/obj
99
.vs
10+
/Test_polyfill/bin
11+
/Test_polyfill/obj
12+
DeftSharp.Windows.Input/DeftSharp.Windows.Input.csproj.user

DeftSharp.Windows.Input.Tests/DeftSharp.Windows.Input.Tests.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0-windows</TargetFramework>
4+
<TargetFrameworks>net8.0-windows;net472</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
57
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
8+
<Nullable>disable</Nullable>
79

810
<IsPackable>false</IsPackable>
911
<IsTestProject>true</IsTestProject>
@@ -32,4 +34,12 @@
3234
<ProjectReference Include="..\DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj" />
3335
</ItemGroup>
3436

35-
</Project>
37+
<ItemGroup>
38+
<Reference Include="WindowsBase" Condition="'$(TargetFramework)' == 'net472'" />
39+
<PackageReference Include="PolySharp" Version="1.15.0" Condition="'$(TargetFramework)' == 'net472'">
40+
<PrivateAssets>all</PrivateAssets>
41+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
42+
</PackageReference>
43+
</ItemGroup>
44+
45+
</Project>

DeftSharp.Windows.Input.sln

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeftSharp.Windows.Input", "DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj", "{3D91851D-784F-4C38-B1F9-CD1D08AA364E}"
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35327.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeftSharp.Windows.Input", "DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj", "{3D91851D-784F-4C38-B1F9-CD1D08AA364E}"
47
EndProject
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF.Playground", "WPF.Playground\WPF.Playground.csproj", "{629A70FA-AB10-42AC-917A-0E86A3EA13D2}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPF.Playground", "WPF.Playground\WPF.Playground.csproj", "{629A70FA-AB10-42AC-917A-0E86A3EA13D2}"
69
EndProject
7-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeftSharp.Windows.Input.Tests", "DeftSharp.Windows.Input.Tests\DeftSharp.Windows.Input.Tests.csproj", "{841090A8-C012-4E7F-86BB-053285D3CD7C}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeftSharp.Windows.Input.Tests", "DeftSharp.Windows.Input.Tests\DeftSharp.Windows.Input.Tests.csproj", "{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_polyfill", "Test_polyfill\Test_polyfill.csproj", "{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}"
813
EndProject
914
Global
1015
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -20,9 +25,19 @@ Global
2025
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
2126
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
2227
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Release|Any CPU.Build.0 = Release|Any CPU
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {7ECB5584-E473-4ECA-BBE6-F41F1DF9B6B7}
2742
EndGlobalSection
2843
EndGlobal

DeftSharp.Windows.Input/DeftSharp.Windows.Input.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net8.0-windows</TargetFramework>
4+
<TargetFrameworks>net8.0-windows;net472</TargetFrameworks>
5+
56
<Nullable>enable</Nullable>
67
<UseWPF>true</UseWPF>
78
<PackageId>DeftSharp.Windows.Input</PackageId>

DeftSharp.Windows.Input/Native/API/MouseAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal static void SetMouseSpeed(int speed)
140140
_ => speed
141141
};
142142

143-
SystemParametersInfo(setMouseSpeedInfo, 0, mouseSpeed, updateIniFile | sendChangeInfo);
143+
SystemParametersInfo(setMouseSpeedInfo, 0, out mouseSpeed, updateIniFile | sendChangeInfo);
144144
}
145145

146146
/// <summary>

DeftSharp.Windows.Input/Native/Interceptors/WindowsInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal abstract class WindowsInterceptor : IRequestedInterceptor
2626
/// <summary>
2727
/// Identifier for the installed WinAPI hook.
2828
/// </summary>
29-
protected nint HookId = nint.Zero;
29+
protected nint HookId = (nint)0;//nint.Zero;
3030

3131
/// <summary>
3232
/// Initializes a new instance of the WindowsListener class.
@@ -61,7 +61,7 @@ public void Unhook()
6161
return;
6262

6363
User32.UnhookWindowsHookEx(HookId);
64-
HookId = nint.Zero;
64+
HookId = (nint)0; //nint.Zero;
6565
_isHandled = false;
6666
}
6767

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Runtime.InteropServices;
8+
using System.Diagnostics;
9+
using System.Collections;
10+
using System.Runtime.CompilerServices;
11+
12+
//namespace DeftSharp.Windows.Input{ }
13+
14+
/// <summary>
15+
/// net472_polyFill
16+
/// </summary>
17+
public static partial class PolyFillExtensions
18+
{
19+
20+
//conditinal compile to get best performance..
21+
#if NETFRAMEWORK
22+
23+
/// <summary>
24+
/// net472_polyFill
25+
/// </summary>
26+
public static IEnumerable<T> TakeLast<T>(this Queue<T> queue, int count) => TakeLast_internal(queue, count);
27+
28+
/// <summary>
29+
/// net472_polyFill
30+
/// </summary>
31+
public static TValue GetValueOrDefault<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
32+
=> dictionary.TryGetValue(key, out var value) ? value : defaultValue;
33+
34+
/// <summary>
35+
/// net472_polyFill
36+
/// </summary>
37+
public static bool TryRemove<TK, TValue>(this ConcurrentDictionary<TK, TValue> dictionary, KeyValuePair<TK, TValue> item)
38+
=> dictionary.TryRemove(item.Key, out _);
39+
40+
#endif
41+
42+
/// <summary>
43+
/// net472_polyFill - nint.Zero
44+
/// </summary>
45+
public static nint nint_Zero => (nint)0;
46+
47+
48+
}
49+
50+
51+
52+
/// <summary>
53+
/// net472_polyFill - not for public use, intented to be consumed in "Unit Tests".
54+
/// </summary>
55+
public static partial class PolyFillExtensions
56+
{
57+
58+
59+
/// <summary>
60+
/// net472_polyFill - internal --- Ex: collection.TakeLast(5);
61+
/// </summary>
62+
internal static IEnumerable<T> TakeLast_internal_viaSO<T>(this IEnumerable<T> source, int N)
63+
{
64+
return source.Skip(Math.Max(0, source.Count() - N));
65+
}
66+
67+
/// <summary>
68+
/// net472_polyFill - internal
69+
/// </summary>
70+
internal static IEnumerable<T> TakeLast_internal<T>(Queue<T> queue, int count)
71+
{
72+
if (queue is null)
73+
throw new ArgumentNullException("source is null ");
74+
75+
if (count <= 0 || queue.Count == 0)
76+
return [];
77+
78+
if (count <= 0)
79+
return Enumerable.Empty<T>();
80+
if (count >= queue.Count)
81+
return queue.ToList();
82+
83+
// isStartIndexFromEnd: true, startIndex: count,
84+
// isEndIndexFromEnd: true, endIndex: 0);
85+
//return queue.Take(queue.Count - count).ToList();
86+
87+
var startIndex = queue.Count - count;
88+
var take = count;
89+
90+
return queue.Skip(startIndex).Take(take).ToList();
91+
92+
}
93+
}

Test_polyfill/PolyFillTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Linq.Expressions;
2+
using System.Linq;
3+
using Xunit;
4+
5+
namespace DeftSharp.Windows.Input;
6+
7+
public sealed class PolyFillTest
8+
{
9+
10+
[Fact]
11+
public async void TakeLast_1()
12+
{
13+
int TakeLast_count = 1;
14+
var que = new Queue<int>(new[] { 1, 2, 3, 4, 5 });
15+
16+
var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
17+
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();
18+
19+
Assert.True(val[0] == valpf[0]);
20+
//await Task.Run(() => { });
21+
}
22+
23+
[Fact]
24+
public async void TakeLast_2()
25+
{
26+
int TakeLast_count = 2;
27+
var que = new Queue<int>(new[] { 1, 2, 3, 4, 5 });
28+
29+
var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
30+
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();
31+
32+
Assert.True(val[0] == valpf[0]);
33+
Assert.True(val[1] == valpf[1]);
34+
}
35+
36+
[Fact]
37+
public async void TakeLast_3()
38+
{
39+
int TakeLast_count = 10;
40+
var que = new Queue<int>(Enumerable.Range(1,100));
41+
42+
var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
43+
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();
44+
45+
Assert.True(val[0] == valpf[0]);
46+
Assert.True(val[4] == valpf[4]);
47+
Assert.True(val[9] == valpf[9]);
48+
}
49+
50+
51+
}

Test_polyfill/Test_polyfill.csproj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Compile Remove="UnitTest1.cs" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
19+
<PackageReference Include="xunit" Version="2.5.3" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Using Include="Xunit" />
29+
</ItemGroup>
30+
31+
</Project>

0 commit comments

Comments
 (0)