I’m trying to create a C# WinRT component for use in metro style applications (win8) and am having trouble with projected types.
It seems the IVector<> and IMap<> data types are inaccessible due to their protection level?
My Sample WinMD Library has one class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Collections;
namespace ClassLibrary1
{
public sealed class Class1
{
public IVector<string> foo()
{
return new List<string>();
}
}
}
I get the following compiler errors:
Inconsistent accessibility: return type 'Windows.Foundation.Collections.IVector<string>' is less accessible than method 'ClassLibrary1.Class1.foo()'
'Windows.Foundation.Collections.IVector<string>' is inaccessible due to its protection level
What am I doing wrong?
EDIT:
Ah ha!
Turns out I should not be using the WinRT type names directly, but using their translated .NET names instead.
The correct code looks like this:
namespace ClassLibrary1
{
public sealed class Class1
{
public IList<string> foo()
{
return new List<string>();
}
}
}
IIterable<T>is projected to .NET asIEnumerable<T>,IVector<T>is projected asIList<T>, andIMap<T>is projected asIDictionary<T>. Projection goes both ways – both for consumption and for authoring – so you should simply always be using the projected versions of those interfaces in your .NET code. When you declare a member as returningIList<T>, it will show up asIVector<T>from WinRT perspective (e.g. from C++/CX). Similarly, if you implementIDictionaryon your class, it’ll show up as implementingIMapin C++/CX.If I remember correctly, you should see all types already mapped as they should be when you use Object Browser for a .NET project.