я хотел бы преобразовать этот код (рабочий код в C#) в C++/CLIДополнительные параметры для FileSystemEventHandler в C++/CLI
static private void onChange(object s, FileSystemEventArgs e, string customArg)
{
Console.WriteLine(e.FullPath);
Console.WriteLine(customArg);
}
static void Main(string[] args)
{
string customArg = "myCustomArg";
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "G:\\";
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.EnableRaisingEvents = true;
// i cannot convert this line in c++/cli
watcher.Changed += (s, e) => onChange(s, e, customArg);
Console.Read();
}
есть мой код в C++/CLI
void FileWatcher::onChanged(Object^ source, FileSystemEventArgs^ e, String^ customArg)
{
Console::WriteLine(e->FullPath);
Console::WriteLine(customArg);
}
int main(int argc, char* argv[])
{
FileSystemWatcher watcher->Path = "G:\\";
watcher->IncludeSubdirectories = true;
watcher->NotifyFilter = static_cast<System::IO::NotifyFilters> (NotifyFilters::LastWrite);
String^ customArg = gcnew String("myArg");
// this line not compile
watcher->Changed += (s, e) = > onChange(s, e, customArg);
//
}
я пытался использовать функцию лямбда, как этот
watcher->Changed += [](Object^ s, FileSystemEventArgs^ e, String^ c) -> void { OnChange(s, e, c); };
, но это не работает, вероятно, делает неправильно
По http://stackoverflow.com/questions/2777445/lambda-expressions-as-clr-net-delegates-event-handlers-in-visual-c-2010 вы не можете назначить лямбда как делегат –