使用 System::DateTime 参数调用 C++/CLI 方法需要“ValueType”;作为参数?
我正在尝试从 C# 调用用 C++/CLI 编写的方法。 C++/CLI 代码用于在给定记录 ID 和 .NET 兼容数据类型的 System::DateTime
对象的情况下更新 Oracle 数据库中的 TIMESTAMP
列对于 Oracle 的 TIMESTAMP
类型。
我调用的方法具有以下原型:
bool ChangeJobUpdateDate (int jobIdIn, System::DateTime^ updateDateIn)
我在我制作的测试项目中添加了对此 DLL 项目的引用;我正在用 C# 编写测试。但是,当我尝试从 C# 单元测试项目中调用此方法时,该函数似乎具有以下方法声明(通过智能感知):
bool ChangeJobUpdateDate (int jobIdIn, ValueType updateDateIn)
我承认对 C++/CLI 不太熟悉,所以我缺少什么吗?
I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code is used to update a TIMESTAMP
column in an Oracle database, given a record ID and the System::DateTime
object which is the .NET compatible data type for Oracle's TIMESTAMP
type.
The method I am calling has the following prototype:
bool ChangeJobUpdateDate (int jobIdIn, System::DateTime^ updateDateIn)
I've added a reference to this DLL project in a test project that I made; I'm writing the tests in C#. However, when I try to call this method from the C# unit test project, the function appears to have the following method declaration (via intellisense):
bool ChangeJobUpdateDate (int jobIdIn, ValueType updateDateIn)
I'm admittedly not that familiar with C++/CLI, so is there something I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这是因为您使用的是
DateTime^
而不仅仅是DateTime
。它是一种值类型,那么为什么要尝试使用引用呢?C# 没有任何方法来表示与值类型关联的装箱引用类型,因此它能做的最好的事情就是
ValueType
- 我怀疑这就是正在发生的事情,尽管我由于我缺乏 C++ 经验,所以不能肯定。尝试一下DateTime
并看看它看起来如何......I suspect it's because you're using
DateTime^
instead of justDateTime
. It's a value type, so why are you trying to use a reference?C# doesn't have any way of representing the boxed reference type associated with a value type, so the best it can do is
ValueType
- I suspect that's what's happening, although I can't say for sure due to my lack of experience with C++. Try justDateTime
and see how that looks...人们对
DateTime^
感到困惑的原因很简单,考虑这段代码:所以基本上你应该使用
*
来访问DateTime^
的值> 并将其传递给您的 C# 方法:当然,如果您打算传递值而不是引用(这可能是大多数人首先想要的)。
The reason people are getting confused over
DateTime^
is quite simple, consider this code:So basically you should use
*
to access the value ofDateTime^
and pass it to your C# method:That is of course if you intended to pass the value instead of a reference (which is what most people probably wanted in the first place).