Last active
September 23, 2020 05:04
-
-
Save DeafMan1983/3c2d32b97a5964e1fa8dfd5b8501c8b6 to your computer and use it in GitHub Desktop.
NativeLong for C# with Dotnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Jens Eckervogt ( aka DeafMan1983 ) | |
* NativeLong for all platform if you use Windows It will work for Windows. But no problem. | |
*/ | |
public interface INativeLong | |
{ | |
long ToNative(); | |
} | |
public class NativeLong : INativeLong | |
{ | |
private readonly long value; | |
protected NativeLong(long value) | |
{ | |
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | |
{ | |
// IntPtr.Size = 4 | |
this.value = (int)value; | |
} | |
else | |
{ | |
// IntPtr.Size = 8 | |
this.value = IntPtr.Size == 8 ? value : (int)value; | |
} | |
} | |
public long ToNative() | |
{ | |
return IntPtr.Size == 8 ? value : (int)value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment