Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support .net 4.7.2 #58

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ DeftSharp.Windows.Input.sln.DotSettings.user
WPF.Playground/bin
WPF.Playground/obj
.vs
/Test_polyfill/bin
/Test_polyfill/obj
DeftSharp.Windows.Input/DeftSharp.Windows.Input.csproj.user
18 changes: 14 additions & 4 deletions DeftSharp.Windows.Input.Tests/DeftSharp.Windows.Input.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFrameworks>net8.0-windows;net472</TargetFrameworks>
<LangVersion>latest</LangVersion>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand Down Expand Up @@ -32,4 +34,12 @@
<ProjectReference Include="..\DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj" />
</ItemGroup>

</Project>
<ItemGroup>
<Reference Include="WindowsBase" Condition="'$(TargetFramework)' == 'net472'" />
<PackageReference Include="PolySharp" Version="1.15.0" Condition="'$(TargetFramework)' == 'net472'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
29 changes: 22 additions & 7 deletions DeftSharp.Windows.Input.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeftSharp.Windows.Input", "DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj", "{3D91851D-784F-4C38-B1F9-CD1D08AA364E}"
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeftSharp.Windows.Input", "DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj", "{3D91851D-784F-4C38-B1F9-CD1D08AA364E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF.Playground", "WPF.Playground\WPF.Playground.csproj", "{629A70FA-AB10-42AC-917A-0E86A3EA13D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPF.Playground", "WPF.Playground\WPF.Playground.csproj", "{629A70FA-AB10-42AC-917A-0E86A3EA13D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeftSharp.Windows.Input.Tests", "DeftSharp.Windows.Input.Tests\DeftSharp.Windows.Input.Tests.csproj", "{841090A8-C012-4E7F-86BB-053285D3CD7C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeftSharp.Windows.Input.Tests", "DeftSharp.Windows.Input.Tests\DeftSharp.Windows.Input.Tests.csproj", "{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_polyfill", "Test_polyfill\Test_polyfill.csproj", "{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,9 +25,19 @@ Global
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{629A70FA-AB10-42AC-917A-0E86A3EA13D2}.Release|Any CPU.Build.0 = Release|Any CPU
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{841090A8-C012-4E7F-86BB-053285D3CD7C}.Release|Any CPU.Build.0 = Release|Any CPU
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEDF1840-E75D-4E55-82D2-C9BBB0CC5C6C}.Release|Any CPU.Build.0 = Release|Any CPU
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E19A38F1-2B3E-4419-8E22-D7B0ADF60219}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7ECB5584-E473-4ECA-BBE6-F41F1DF9B6B7}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion DeftSharp.Windows.Input/DeftSharp.Windows.Input.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFrameworks>net8.0-windows;net472</TargetFrameworks>

<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<PackageId>DeftSharp.Windows.Input</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion DeftSharp.Windows.Input/Native/API/MouseAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ internal static void SetMouseSpeed(int speed)
_ => speed
};

SystemParametersInfo(setMouseSpeedInfo, 0, mouseSpeed, updateIniFile | sendChangeInfo);
SystemParametersInfo(setMouseSpeedInfo, 0, out mouseSpeed, updateIniFile | sendChangeInfo);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal abstract class WindowsInterceptor : IRequestedInterceptor
/// <summary>
/// Identifier for the installed WinAPI hook.
/// </summary>
protected nint HookId = nint.Zero;
protected nint HookId = (nint)0;//nint.Zero;

/// <summary>
/// Initializes a new instance of the WindowsListener class.
Expand Down Expand Up @@ -61,7 +61,7 @@ public void Unhook()
return;

User32.UnhookWindowsHookEx(HookId);
HookId = nint.Zero;
HookId = (nint)0; //nint.Zero;
_isHandled = false;
}

Expand Down
93 changes: 93 additions & 0 deletions DeftSharp.Windows.Input/net472_polyFill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections;
using System.Runtime.CompilerServices;

//namespace DeftSharp.Windows.Input{ }

/// <summary>
/// net472_polyFill
/// </summary>
public static partial class PolyFillExtensions
{

//conditinal compile to get best performance..
#if NETFRAMEWORK

/// <summary>
/// net472_polyFill
/// </summary>
public static IEnumerable<T> TakeLast<T>(this Queue<T> queue, int count) => TakeLast_internal(queue, count);

/// <summary>
/// net472_polyFill
/// </summary>
public static TValue GetValueOrDefault<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
=> dictionary.TryGetValue(key, out var value) ? value : defaultValue;

/// <summary>
/// net472_polyFill
/// </summary>
public static bool TryRemove<TK, TValue>(this ConcurrentDictionary<TK, TValue> dictionary, KeyValuePair<TK, TValue> item)
=> dictionary.TryRemove(item.Key, out _);

#endif

/// <summary>
/// net472_polyFill - nint.Zero
/// </summary>
public static nint nint_Zero => (nint)0;


}



/// <summary>
/// net472_polyFill - not for public use, intented to be consumed in "Unit Tests".
/// </summary>
public static partial class PolyFillExtensions
{


/// <summary>
/// net472_polyFill - internal --- Ex: collection.TakeLast(5);
/// </summary>
internal static IEnumerable<T> TakeLast_internal_viaSO<T>(this IEnumerable<T> source, int N)
{
return source.Skip(Math.Max(0, source.Count() - N));
}

/// <summary>
/// net472_polyFill - internal
/// </summary>
internal static IEnumerable<T> TakeLast_internal<T>(Queue<T> queue, int count)
{
if (queue is null)
throw new ArgumentNullException("source is null ");

if (count <= 0 || queue.Count == 0)
return [];

if (count <= 0)
return Enumerable.Empty<T>();
if (count >= queue.Count)
return queue.ToList();

// isStartIndexFromEnd: true, startIndex: count,
// isEndIndexFromEnd: true, endIndex: 0);
//return queue.Take(queue.Count - count).ToList();

var startIndex = queue.Count - count;
var take = count;

return queue.Skip(startIndex).Take(take).ToList();

}
}
51 changes: 51 additions & 0 deletions Test_polyfill/PolyFillTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Linq.Expressions;
using System.Linq;
using Xunit;

namespace DeftSharp.Windows.Input;

public sealed class PolyFillTest
{

[Fact]
public async void TakeLast_1()
{
int TakeLast_count = 1;
var que = new Queue<int>(new[] { 1, 2, 3, 4, 5 });

var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();

Assert.True(val[0] == valpf[0]);
//await Task.Run(() => { });
}

[Fact]
public async void TakeLast_2()
{
int TakeLast_count = 2;
var que = new Queue<int>(new[] { 1, 2, 3, 4, 5 });

var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();

Assert.True(val[0] == valpf[0]);
Assert.True(val[1] == valpf[1]);
}

[Fact]
public async void TakeLast_3()
{
int TakeLast_count = 10;
var que = new Queue<int>(Enumerable.Range(1,100));

var val = Enumerable.TakeLast(que, TakeLast_count).ToList(); // net8 original Linq
var valpf = PolyFillExtensions.TakeLast(que, TakeLast_count).ToList();

Assert.True(val[0] == valpf[0]);
Assert.True(val[4] == valpf[4]);
Assert.True(val[9] == valpf[9]);
}


}
31 changes: 31 additions & 0 deletions Test_polyfill/Test_polyfill.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Remove="UnitTest1.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeftSharp.Windows.Input\DeftSharp.Windows.Input.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>