我怎样才能得到接近非空的引用类型在C#今天? [英] How can I get close to non-nullable reference types in C# today?

查看:112
本文介绍了我怎样才能得到接近非空的引用类型在C#今天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过许多非空的的问题和答案。它看起来像去接近非可空类型的C#(4.0)的最佳方式是全碟的非空<> 破解

I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack.

但是,似乎C ++ / CLI已经解决了许多问题,通过支持托管引用:富%(而不是本地C ++ 富和放大器; )。编译器,使这项工作,加入 modreq(IsImplicitlyDereferenced)的说法。试图调用从C#的结果以这样一种功能:

However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo&). The compiler makes this work by adding modreq(IsImplicitlyDereferenced) to the argument. Trying to call such a function from C# results in:

'<FunctionName>' is not supported by the language

有没有什么更好的那么的非空&LT;?>

有什么办法(合理 - 即W / O使用反射)调用C ++ / CLI方法富::方法(酒吧%)从C#?

Is there any way to (reasonably--i.e., w/o using reflection) call a C++/CLI method Foo::Method(Bar%) from C#?

好像目前还没有什么好过的非空&LT;> 的...我想我会得到一些评论对C ++ / CLI的东西,因为它已经具有至少一个部分解决方案。

[edit] It seems there is currently nothing better than NonNullable<>...I wish I would have gotten some comments on the C++/CLI stuff as it already has at least a partial solution.

推荐答案

我碰到的这几次......我还没有发现任何东西比飞碟双向的解决方案更好。它解决了所有我遇到的情况,所以我必须给我的票。

I've run into this a few times...I've yet to find anything better than Skeet's solution. It's solved all the cases I've come across, so I have to give it my vote.

我同意这是一个有点哈克的情况,我们不得不求助于那个......但他的解决方法不解决问题。

I agree it's a bit of a hacky situation that we have to resort to that...but his fix does solve the problem.

这篇关于我怎样才能得到接近非空的引用类型在C#今天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆