这个C ++代码的C#等价物是什么?
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;
}
答案 0 :(得分:4)
答案 1 :(得分:2)
这是一个粗略翻译,仅用于说明目的:
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
已更改为void
,因为我们在C#中使用例外而不是错误代码; EDSCALLBACK
定义为__stdcall
,这与此无关;代码仅当存在所有隐含的类和方法时才有效;惯用的C#将使用event
/ EventHandler< T> / EventArgs而不是“NotifyObservers”方法;我假设您不希望与C ++进行任何互操作)。