[bcl] Base type update to match netstandard apis
[mono.git] / mcs / class / System / System.IO / FileSystemWatcher.cs
index 0d293e53188b4f6155380ba838edf3443f1f7117..43d3c2f362e1f681a13c46a53265585006de6e6a 100644 (file)
@@ -375,60 +375,54 @@ namespace System.IO {
                        ErrorEvent,
                        RenameEvent
                }
-                       
-               protected void OnChanged (FileSystemEventArgs e)
+               private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype)
                {
-                       if (Changed == null)
+                       if (ev == null)
                                return;
 
-                       if (synchronizingObject == null)
-                               Changed (this, e);
-                       else
-                               synchronizingObject.BeginInvoke (Changed, new object[] { this, e });
+                       if (synchronizingObject == null) {
+                               foreach (var target in ev.GetInvocationList()) {
+                                       switch (evtype) {
+                                       case EventType.RenameEvent:
+                                               ((RenamedEventHandler)target).BeginInvoke (this, (RenamedEventArgs)arg, null, null);
+                                               break;
+                                       case EventType.ErrorEvent:
+                                               ((ErrorEventHandler)target).BeginInvoke (this, (ErrorEventArgs)arg, null, null);
+                                               break;
+                                       case EventType.FileSystemEvent:
+                                               ((FileSystemEventHandler)target).BeginInvoke (this, (FileSystemEventArgs)arg, null, null);
+                                               break;
+                                       }
+                               }
+                               return;
+                       }
+                       
+                       synchronizingObject.BeginInvoke (ev, new object [] {this, arg});
                }
 
-               protected void OnCreated (FileSystemEventArgs e)
+               protected void OnChanged (FileSystemEventArgs e)
                {
-                       if (Created == null)
-                               return;
+                       RaiseEvent (Changed, e, EventType.FileSystemEvent);
+               }
 
-                       if (synchronizingObject == null)
-                               Created (this, e);
-                       else
-                               synchronizingObject.BeginInvoke (Created, new object[] { this, e });
+               protected void OnCreated (FileSystemEventArgs e)
+               {
+                       RaiseEvent (Created, e, EventType.FileSystemEvent);
                }
 
                protected void OnDeleted (FileSystemEventArgs e)
                {
-                       if (Deleted == null)
-                               return;
-
-                       if (synchronizingObject == null)
-                               Deleted (this, e);
-                       else
-                               synchronizingObject.BeginInvoke (Deleted, new object[] { this, e });
+                       RaiseEvent (Deleted, e, EventType.FileSystemEvent);
                }
 
-               internal void OnError (ErrorEventArgs e)
+               protected void OnError (ErrorEventArgs e)
                {
-                       if (Error == null)
-                               return;
-
-                       if (synchronizingObject == null)
-                               Error (this, e);
-                       else
-                               synchronizingObject.BeginInvoke (Error, new object[] { this, e });
+                       RaiseEvent (Error, e, EventType.ErrorEvent);
                }
 
                protected void OnRenamed (RenamedEventArgs e)
                {
-                       if (Renamed == null)
-                               return;
-
-                       if (synchronizingObject == null)
-                               Renamed (this, e);
-                       else
-                               synchronizingObject.BeginInvoke (Renamed, new object[] { this, e });
+                       RaiseEvent (Renamed, e, EventType.RenameEvent);
                }
 
                public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType)
@@ -458,6 +452,11 @@ namespace System.IO {
                        return result;
                }
 
+               internal void DispatchErrorEvents (ErrorEventArgs args)
+               {
+                       OnError (args);
+               }
+
                internal void DispatchEvents (FileAction act, string filename, ref RenamedEventArgs renamed)
                {
                        if (waiting) {