.NET类库中的引用参数 [英] Reference argument in a .NET class library
问题描述
我用C ++编写了一个大型.NET类库(使用旧语法)。它工作得非常好,并且已经在C ++,C#和Visual Basic中使用了一段时间。
无论如何,我刚刚发现任何采用参数的方法都是对基本类型的引用不会暴露给Visual Basic。
让C ++声明为
< span class =code-keyword> void mVizNET :: Histogram :: Range(int& Minimum,int& Maximum);
C ++对象浏览器将其显示为
System.Void范围(系统。 Int32 最小值,系统。 Int32 最大值)
mVizNET.Histogram的成员
(奇怪的是,缺少 ref
关键字) 。
C#对象浏览器将其显示为
public static void 范围(int * Minimum,int * Maximum)
成员of mVizNET.Histogram
(奇怪的是,参数作为指针传递)。
但是Visual Basic对象浏览器根本没有显示它:(
有没有人解释?是否有一个特殊的属性我应该给这些参考参数更好地揭示它们?使用旧语法是否无法使用此功能?是否支持新语法?
我找到了一种解决方法。如果您使用.NET类型而不是本机类型,则可以交换引用的指针。
如果您将原型更改为
void mVizNET :: Histogram :: Range(Int32 * Minimum,Int32 * Maximum);
然后方法显示为
System.Void范围(System.Int32 Minimum,System.Int32 Maximum)
mVizNET.Histogram成员
public void 范围( ref int 最小值, ref int 最大值)
mVizNET.Histogram成员
公共 Sub 范围( ByRef 最小 As 整数, ByRef 最大作为 整数)
成员:mVizNET.Histogram
这就是我需要的。 (实际上,C ++浏览器还显示了mVizNET.Histogram.Range(System.Int32 @,System.Int32 @)
声明,其中@
可能代表C ++ / CLI参考)。
请注意引用的声明如
void mVizNET :: Histogram :: Range(Int32& Minimum,Int32& Maximum);
也可以,但这次不被C#浏览器识别!
I have written a large .NET class library in C++ (using old syntax). It works very well and has been in use with C++, C# and Visual Basic for a while.
Anyway, I just discovered that any method taking an argument that is a reference to a base type is not exposed to Visual Basic.
Let the C++ declaration be
void mVizNET::Histogram::Range(int& Minimum, int& Maximum);
The C++ object browser shows it as
System.Void Range(System.Int32 Minimum, System.Int32 Maximum)
Member of mVizNET.Histogram
(strangely, the ref
keyword is missing).
The C# object browser shows it as
public static void Range(int* Minimum, int* Maximum)
Member of mVizNET.Histogram
(strangely, the argument is passed as a pointer).
But the Visual Basic object browser does not show it at all :(
Has anyone an explanation ? Is there a special attribute I should give those reference arguments to better expose them ? Is this feature unavailable using the old syntax ? Is it supported in the new syntax ?
I have found a workaround. References can be traded for pointers, provided you use a .NET type instead of a native one.
If you change the prototype to
void mVizNET::Histogram::Range(Int32* Minimum, Int32* Maximum);
then the method appears as
System.Void Range(System.Int32 Minimum, System.Int32 Maximum) Member of mVizNET.Histogram
public void Range(ref int Minimum, ref int Maximum) Member of mVizNET.Histogram
Public Sub Range(ByRef Minimum As Integer, ByRef Maximum As Integer) Member of: mVizNET.Histogram
which is what I need. (Actually, the C++ browser also shows amVizNET.Histogram.Range(System.Int32@, System.Int32@)
declaration, where the@
possibly stands for a C++/CLI reference).
Note that a declaration with references like
void mVizNET::Histogram::Range(Int32& Minimum, Int32& Maximum);
will also work, but is not recognized by the C# browser this time!
这篇关于.NET类库中的引用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!