3

I have created a WinRT component in C# which accepts a collection as a parameter.

namespace MyNamespace {
  public sealed class MyClass {
    public MyFunction(IReadOnlyDictionary<string, string> properties) {
    }
  }
}

I am trying to use this component in javascript as follows:

var x = new MyNamespace.MyClass();
x.MyFunction({'aaa': 'bbbb'});

I am not sure why this is not working. Any Ideas?

2
  • My first thought is possibly that {'aaa': 'bbbb'} != IReadOnlyDictionary<string, string> Commented Jan 5, 2013 at 0:00
  • I tried IDictionary Instead of IReadOnlyDictionary and it doesn't work. I also tried to see what the definition looks like after the compilation of component takes place and the method signature looks like Windows.Foundation.Collections.IMap<string, string> but I don't know how to create such an object in javascript Commented Jan 5, 2013 at 0:08

1 Answer 1

1

I think this is your answer.

var ps = new Windows.Foundation.Collections.PropertySet();
ps['aaa'] = "bbb";

var x = new MyNamespace.MyClass();
x.MyFunction(ps);

"Your WinRT component will need to expose (or reuse) a concrete class implementing the specific instantiation of IMap that you need..."

Sign up to request clarification or add additional context in comments.

2 Comments

I think this works but it is quite inconvenient since I just have to re-implement all the dictionary methods again :( (marked your answer as answer since it at least works)
Well you might be able to overload the methods to accept the javascript compatable object, reformat it, then pass it to the original method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.