I am trying to write a managed wrapper class in order to perform interop and conversion for a native class. I wrote something similar to this in my interop library;
namespace MyNamespace {
public ref class MyClass {
public:
static void MyMethod(double myArray[]);
}
}
However when I reference this library from my C# application, the interface has changed. If I F12 on the class in C# I get the regenerated interface MyClass [from metadata] which looks like this;
namespace MyNamespace {
public class MyClass {
public static void MyMethod(double myArray*);
}
}
Why did the compiler convert the array into a pointer? How can I get the compiler to correctly expose this argument as an array rather than a pointer?
If I want to use the class in this way then I would have to get a pointer to the managed array in an unsafe context, which I don't want to do.
Update
When I do typeof(double[]) in C# I get;
{Name = "Double[]" FullName = "System.Double[]"}
Assembly: {mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
AssemblyQualifiedName: "System.Double[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
Attributes: Public | Sealed | Serializable
BaseType: {Name = "Array" FullName = "System.Array"}
...}
So I understand the comments suggesting that I need a System.Array. However, my question still stands, how do I declare a System.Double[] array in the interop class? Simply putting MyMethod(System::Double[] myArray) doesn't work...
System.Arrayfor arrays, which C# does and in that case it just expects a pointer to the data instead.double[]argument by some .net array type. It should be possible to use such a type in C++/CLISystem.Arrayis typeless. I want the argument to be interpreted as adouble[]not aSystem.Array.double[]and it can be passed in an argument, so how do I get the ref class to expose it as adouble []instead of adouble*?