Skip to content

Instantly share code, notes, and snippets.

@DeafMan1983
Last active September 23, 2020 05:04
Show Gist options
  • Select an option

  • Save DeafMan1983/3c2d32b97a5964e1fa8dfd5b8501c8b6 to your computer and use it in GitHub Desktop.

Select an option

Save DeafMan1983/3c2d32b97a5964e1fa8dfd5b8501c8b6 to your computer and use it in GitHub Desktop.

Revisions

  1. DeafMan1983 revised this gist Sep 23, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions NativeLong.cs
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,11 @@
    * 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;
  2. DeafMan1983 created this gist Sep 23, 2020.
    27 changes: 27 additions & 0 deletions NativeLong.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    /*
    * Jens Eckervogt ( aka DeafMan1983 )
    * NativeLong for all platform if you use Windows It will work for Windows. But no problem.
    */
    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;
    }
    }