Ty *_*ton 5 c# winapi microsoft-metro windows-8 windows-runtime
我正在尝试创建一个用于Metro风格应用程序(win8)的C#WinRT组件,并且我遇到了投影类型的问题.
由于其保护级别,IVector <>和IMap <>数据类似乎无法访问?
我的示例WinMD库有一个类:
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>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下编译器错误:
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
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
编辑:
啊哈!
事实证明我不应该直接使用WinRT类型名称,而是使用他们翻译的.NET名称.
正确的代码如下所示:
namespace ClassLibrary1
{
public sealed class Class1
{
public IList<string> foo()
{
return new List<string>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
IIterable<T>
被预测为.NET IEnumerable<T>
,IVector<T>
被投射为IList<T>
,并被IMap<T>
预测为IDictionary<T>
.投影有两种方式 - 无论是用于消费还是用于创作 - 因此您应该始终在.NET代码中使用这些接口的预计版本.当您将成员声明为返回时IList<T>
,它将IVector<T>
从WinRT透视图中显示(例如,从C++/CX).同样,如果IDictionary
在类上实现,它将显示为IMap
在C++/CX中实现.
如果我没记错的话,当您使用.NET项目的对象浏览器时,您应该看到已经映射的所有类型.
归档时间: |
|
查看次数: |
3632 次 |
最近记录: |