Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

ObservableCollection<string> not working but List<string> is working #288

Closed
Alphapage opened this issue Nov 12, 2013 · 7 comments
Closed

Comments

@Alphapage
Copy link

Hello,
I'd like to use ObservableCollection instead of List to get changed notifications easily, but it doesn't seems to work.
Here is my little test case:
System.Collections.ObjectModel.ObservableCollection obs = new System.Collections.ObjectModel.ObservableCollection() { "str1", "str2" };
obs.Add("str3");
System.Diagnostics.Debug.WriteLine("count obs:" + obs.Count);
System.Collections.Generic.List list = new System.Collections.Generic.List() { "str1", "str2" };
list.Add("str3");
System.Diagnostics.Debug.WriteLine("count list:" + list.Count);

Thanks in advance for your help.

@Alphapage
Copy link
Author

Hello again,
Is there any tutorial to explain how to do to implement a new feature ?
I suspect I need to add custom code in bootstrap.js.
How do you debug such a class ?
Do you implement it outside of js file using JSReplacemment or Verbatim or do you use pure javascript ?

For now, I can only add some test cases:
#291

@kg
Copy link
Member

kg commented Nov 26, 2013

There is no tutorial but there are some past issues on the JSIL project here on github where I have answered questions; you might want to look through those.

Related:
#158
#171

At some point I may write a comprehensive tutorial. At present, feel free to ask specific questions.

Debugging is done using the JS debuggers in Firefox, IE and Chrome. Most features are implemented in the .js files, by hand, using Externals. A few features are implemented using proxies (see the Proxies projects in the JSIL sln) in which case they're a mix of JSReplacement and cross-compiled C#.

@Alphapage
Copy link
Author

I try to debug PropertyChangedEventArgs which seems possible to me (ObservableCollection is more advanced one I think). If I switch to this function in System.js, the PropertyChangedEventArgs constructor error is never thrown:

(function PropertyChangedEventArgs$Members () {
  var $, $thisType;
  var $T00 = function () {
    return ($T00 = JSIL.Memoize($asm03.System.String)) ();
  };
  var $T01 = function () {
    return ($T01 = JSIL.Memoize($asm03.System.EventArgs)) ();
  };

  function PropertyChangedEventArgs__ctor (propertyName) {
    $T01().prototype._ctor.call(this);
    this.propertyName = propertyName;
  };

  function PropertyChangedEventArgs_get_PropertyName () {
    return this.propertyName;
  };
  JSIL.MakeClass($asm03.TypeRef("System.EventArgs"), "System.ComponentModel.PropertyChangedEventArgs", true, [], function ($interfaceBuilder) {
    $ = $interfaceBuilder;

    $.Method({Static:false, Public:true }, ".ctor", 
      new JSIL.MethodSignature(null, [$.String], []), 
      PropertyChangedEventArgs__ctor
    );

    $.Method({Static:false, Public:true , Virtual:true }, "get_PropertyName", 
      new JSIL.MethodSignature($.String, [], []), 
      PropertyChangedEventArgs_get_PropertyName
    );

    $.Field({Static:false, Public:false, ReadOnly:true }, "propertyName", $.String); 
    $.Property({Static:false, Public:true , Virtual:true }, "PropertyName", $.String);
    //$.ExternalMethod({Static:false, Public:true }, ".ctor", 
    //  new JSIL.MethodSignature(null, [$.String], [])
    //)
    //  .Attribute($asm04.TypeRef("__DynamicallyInvokableAttribute"))
    //  .Attribute($asm03.TypeRef("System.Runtime.TargetedPatchingOptOutAttribute"), function () { return ["Performance critical to inline this type of method across NGen image boundaries"]; });

    //$.ExternalMethod({Static:false, Public:true , Virtual:true }, "get_PropertyName", 
    //  new JSIL.MethodSignature($.String, [], [])
    //)
    //  .Attribute($asm04.TypeRef("__DynamicallyInvokableAttribute"))
    //  .Attribute($asm03.TypeRef("System.Runtime.TargetedPatchingOptOutAttribute"), function () { return ["Performance critical to inline this type of method across NGen image boundaries"]; });

    //$.Field({Static:false, Public:false, ReadOnly:true }, "propertyName", $.String); 
    //$.Property({Static:false, Public:true , Virtual:true }, "PropertyName", $.String)
    //  .Attribute($asm04.TypeRef("__DynamicallyInvokableAttribute"));

    return function (newThisType) { $thisType = newThisType; }; 
  })
    .Attribute($asm04.TypeRef("__DynamicallyInvokableAttribute"));

})();

From there, I don't know how to tell the compiler to use this function instead of previous one.

@Alphapage
Copy link
Author

I'm studying...
How to call System.Collections.ArrayList/ReadOnlyList in bootstrap.js ?
I need to call the constructor from bootstrap to return a new System.Collections.ArrayList.ReadOnlyList(list).

@wklingler
Copy link

Why was this closed? I see some possible workarounds but ObservableCollections still do not work with JSIL.

@iskiselev
Copy link
Member

Issue was closed by original reporter. ObservableCollections is not implemented in JSIL bootstrap. However, I believe it should work with translated BCL (System assembly).

@kg
Copy link
Member

kg commented Apr 13, 2016

If it doesn't work in translated BCL, definitely file an issue about that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants