Skip to content

Instantly share code, notes, and snippets.

@DeafMan1983
Last active September 23, 2020 05:04
Show Gist options
  • Save DeafMan1983/3c2d32b97a5964e1fa8dfd5b8501c8b6 to your computer and use it in GitHub Desktop.
Save DeafMan1983/3c2d32b97a5964e1fa8dfd5b8501c8b6 to your computer and use it in GitHub Desktop.
NativeLong for C# with Dotnet
/*
* 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