예제 #1
0
 private void DisposeHelperObject()
 {
     if(helperObject != null) {
         helperObject.Dispose();
         helperObject = null;
     }
 }
예제 #2
0
        /// <summary>
        /// Checks if the file matches the conditions imposed by the filters
        /// </summary>
        /// <param name="file">The file to check.</param>
        public bool AllowFile(string file)
        {
            // check the parameters
            Debug.AssertNotNull(file, "File is null");

            // allow all files if the Filter is disabled
            if(_enabled == false) {
                return true;
            }

            // use the expression tree to Filter the file
            if(_expressionTree != null) {
                return EvaluateTree(file);
            }

            // perform basic filtering
            int count = filters.Count;
            bool result = true;
            helperObject = null;

            for(int i = 0; i < count; i++) {
                FilterBase filter = filters[i];

                // skip disabled filters
                if(filter.Enabled == false) {
                    continue;
                }

                filter.HelperObject = helperObject;
                result &= filter.Allow(file);
                helperObject = filter.HelperObject;
                filter.HelperObject = null;

                // return immediately if result is false
                if(result == false) {
                    DisposeHelperObject();
                    return false;
                }
            }

            // dispose the helper
            DisposeHelperObject();
            return result;
        }