What does custom C# class map to in C++?

289 views Asked by At

I need to pass data from C# to C++ in my WP8 app.

I have learned that there's a mapping from .NET to Windows Runtime Component. For instance:

System.String maps to Platform::String^.

IReadOnlyList<String> maps to Windows::Foundation::Collections::IVectorView<Platform::String ^>^.

But what does custom (i.e. user-defined) class map to?

E.g. I have in C# side

public class MyDesc
{
    public string m_bitmapName { get; set; }
    public string m_link { get; set; }
}
public IReadOnlyList<MyDesc> getDescs()
{
    return new List<MyDesc>();
}

What do I call it on C++ side? In other words, what do I substitute "???" to below:

virtual Windows::Foundation::Collections::IVectorView<??? ^>^ getDescs();
1

There are 1 answers

0
robwirving On BEST ANSWER

You need to declare the MyDesc class in the C++/CX component that your C# code is referencing.

So in your C++/CX you would have:

namespace WinRTComponent
{
    public ref class MyDesc sealed
    {
    public:
        property Platform::String^ BitmapName
        {
            Platform::String^ get() { return m_bitmapName; }
            void set(Platform::String^ bitmapName) { m_bitmapName = bitmapName; }
        }
        property Platform::String^ Link
        {
            Platform::String^ get() { return m_link; }
            void set(Platform::String^ link) { m_link = link; }
        }

    private:
        Platform::String^ m_bitmapName;
        Platform::String^ m_link;
    };
}

Then you'll be able to pass a vector/list of MyDesc objects between C++/CX and C#