What is the C# equivalent of this C++ code?
private:
static EdsError EDSCALLBACK ProgressFunc (
EdsUInt32 inPercent,
EdsVoid * inContext,
EdsBool * outCancel
)
{
Command *command = (Command *)inContext;
CameraEvent e("ProgressReport", &inPercent);
command->getCameraModel()->notifyObservers(&e);
return EDS_ERR_OK;
}
This is a rough translation for illustration purposes:
private static void ProgressFunc(uint percent, object context, out bool cancel)
{
Command command = (Command)context;
CameraEvent e = new CameraEvent("ProgressReport", percent);
command.GetCameraModel().NotifyObservers(e);
cancel = false;
}
( EdsError
has been changed to void
, because we use exceptions in C# instead of error codes; EDSCALLBACK
is defined as __stdcall
which is irrelevant here; the code only works if all implied classes and methods exist; idiomatic C# would be the use of event
/EventHandler<T>/EventArgs instead of a "NotifyObservers" method; I assume you don't want to do any interop with C++).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.