Announcement

Collapse
No announcement yet.

UInt8 as generic type

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    UInt8 as generic type

    How can I declare a generic collection where value or key is Uint8[]?
    useTypedArrays is set to true.

    Dictionary<byte[],.. emits to Dictionary$2(System.Array.type(System.Byte))…
    var bytes=new byte[n] emits to Uint8[n], as expected

    For now, I will make a workaround, with a wrapper class, for the uint8 array, but if I have overlooked something, please let me know.

    Any help or hints are appreciated.
    Thanks in advance!
    Jens
    Last edited by geoffrey.mcgill; 2019-04-09 @ 05:45 PM.

    #2
    Hi. Can you share a https://dotnetfiddle.net sample demonstrating a simple scenario? Also, a https://deck.net sample demonstrating the same scenario would be helpful too, even if it doesn't actually work.

    Comment


      #3
      Hi,
      I wish I could share a https://deck.net sample, but I cannot see how to set the useTypedArrays flag in that environment.

      Below is a very small sample of declarations with c# input and JS output from Bridge.

      // C# code:
      public class Demo
          {
              private readonly byte[] byteArray = new byte[8];
              private readonly List<byte[]> byteArrayList = new List<byte[]>();
          }
      Here is the output from Bridge when useTypedArrays is set to false:

       Bridge.define("Demo.Demo", {
              fields: {
                  byteArray: null,
                  byteArrayList: null
              },
              ctors: {
                  init: function () {
                      this.byteArray = System.Array.init(8, 0, System.Byte);
                      this.byteArrayList = new (System.Collections.Generic.List$1(System.Array.type(System.Byte))).ctor();
                  }
              }
          });
      In this case System.Array.type(System.Byte) is the type of the byteArray and the content of the byteArrayList. This is as expected.

      With useTypedArrays set to true, however, the output becomes:

        Bridge.define("Demo.Demo", {
              fields: {
                  byteArray: null,
                  byteArrayList: null
              },
              ctors: {
                  init: function () {
                      this.byteArray = System.Array.init(new Uint8Array(8), System.Byte);
                      this.byteArrayList = new (System.Collections.Generic.List$1(System.Array.type(System.Byte))).ctor();
                  }
              }
          });
      In this case the byteArray becomes a typedArray containing UInt8Array as expected, while the byteArrayList remains unchanged.
      I would expect all declarations of byte arrays to become typedArrays. Is it something I have misunderstood?

      Regards Jens
      Last edited by geoffrey.mcgill; 2019-04-03 @ 04:49 AM.

      Comment


        #4
        Hello JensTangen

        I'm not sure how much the UseTypedArrays feature can interop with further C#-focused code, as it treads more to a javascript approach and, initially it is more likely to work with code more focused to JavaScript; and may have even more issues with C# tests like isArray(), as pointed in the issue bridgedotnet/Bridge#772 where the feature was introduced. Mixing up with generics seems to be another point that would need implementation before it works.

        I've logged your report under issue #3891 in our github issues tracker. Whenever we get that implemented, we'd post a follow-up here. Pull requests are, as always, welcome!
        Last edited by fabricio.murta; 2019-04-09 @ 05:44 PM.

        Comment

        Working...
        X