I have a "JulianDate" struct that I've written in C#, and it has a custom explicit operator to DateTime from the .NET Library. I've used this explicit operator several times in my C# code and it works with no issues.
I now want to use the same explicit operator in my C++/CLI code, but I am unable to figure out how.
I've tried:
DateTime^ dt = (DateTime^)jdate;
(compiles, but I get an InvalidCastException)DateTime^ dt = safe_cast<DateTime^>(jdate);
(I get a compiler error)DateTime^ dt = DateTime(*jdate);
(compiles, but dt has wrong data: 1/1/0001 12:00AM)DateTime^ dt = dynamic_cast<DateTime^>(jdate);
(compiles, but returns null)
For the safe cast, I'm getting the following error:
`Error 4 error C2682: cannot use 'safe_cast' to convert from 'Solution::Common::JulianDate ^' to 'System::DateTime ^' C:\Users\9a3eedi\Documents\Solution\Wrapper\Wrapper.cpp 75 Wrapper
What is the proper method of performing an explicit cast? Or is the reason why it's not working is due to me working with structs and not with classes? Or perhaps C++/CLI does not support C# explicit operators?