System.IO.FileSystemWatcher.TranslateFilters C# (CSharp) Method

TranslateFilters() private static method

Maps the FileSystemWatcher's NotifyFilters enumeration to the corresponding Interop.Sys.NotifyEvents values.
private static TranslateFilters ( NotifyFilters filters ) : Interop.Sys.NotifyEvents
filters NotifyFilters The filters provided the by user.
return Interop.Sys.NotifyEvents
        private static Interop.Sys.NotifyEvents TranslateFilters(NotifyFilters filters)
        {
            Interop.Sys.NotifyEvents result = 0;

            // We always include a few special inotify watch values that configure
            // the watch's behavior.
            result |=
                Interop.Sys.NotifyEvents.IN_ONLYDIR |     // we only allow watches on directories
                Interop.Sys.NotifyEvents.IN_EXCL_UNLINK;  // we want to stop monitoring unlinked files

            // For the Created and Deleted events, we need to always
            // register for the created/deleted inotify events, regardless
            // of the supplied filters values. We explicitly don't include IN_DELETE_SELF.  
            // The Windows implementation doesn't include notifications for the root directory, 
            // and having this for subdirectories results in duplicate notifications, one from 
            // the parent and one from self.
            result |= 
                Interop.Sys.NotifyEvents.IN_CREATE | 
                Interop.Sys.NotifyEvents.IN_DELETE;

            // For the Changed event, which inotify events we subscribe to
            // are based on the NotifyFilters supplied.
            const NotifyFilters filtersForAccess =
                NotifyFilters.LastAccess;
            const NotifyFilters filtersForModify =
                NotifyFilters.LastAccess |
                NotifyFilters.LastWrite |
                NotifyFilters.Security |
                NotifyFilters.Size;
            const NotifyFilters filtersForAttrib =
                NotifyFilters.Attributes |
                NotifyFilters.CreationTime |
                NotifyFilters.LastAccess |
                NotifyFilters.LastWrite |
                NotifyFilters.Security |
                NotifyFilters.Size;
            if ((filters & filtersForAccess) != 0)
            {
                result |= Interop.Sys.NotifyEvents.IN_ACCESS;
            }
            if ((filters & filtersForModify) != 0)
            {
                result |= Interop.Sys.NotifyEvents.IN_MODIFY;
            }
            if ((filters & filtersForAttrib) != 0)
            {
                result |= Interop.Sys.NotifyEvents.IN_ATTRIB;
            }

            // For the Rename event, we'll register for the corresponding move inotify events if the 
            // caller's NotifyFilters asks for notifications related to names.
            const NotifyFilters filtersForMoved =
                NotifyFilters.FileName |
                NotifyFilters.DirectoryName;
            if ((filters & filtersForMoved) != 0)
            {
                result |=
                    Interop.Sys.NotifyEvents.IN_MOVED_FROM |
                    Interop.Sys.NotifyEvents.IN_MOVED_TO;
            }

            return result;
        }