/// <summary> /// Creates a condition node that is a logical negation (NOT) of another condition /// (a subnode of this node). /// </summary> /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param> /// <param name="simplify">True to logically simplify the result if possible; False otherwise. /// In a query builder scenario, simplyfy should typically be set to false.</param> /// <returns>New SearchCondition</returns> public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplify) { if (conditionToBeNegated == null) { throw new ArgumentNullException(nameof(conditionToBeNegated)); } // Same as the native "IConditionFactory:MakeNot" method IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition result; try { HResult hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplify, out result); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(new SearchCondition(result)); }
/// <summary> /// Creates a condition node that is a logical negation (NOT) of another condition /// (a subnode of this node). /// </summary> /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param> /// <param name="simplyfy">True to logically simplify the result if possible; False otherwise. /// In a query builder scenario, simplyfy should typically be set to false.</param> /// <returns>New SearchCondition</returns> public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplyfy) { // Same as the native "IConditionFactory:MakeNot" method IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition result; try { HRESULT hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplyfy, out result); if (!CoreErrorHelper.Succeeded((int)hr)) { Marshal.ThrowExceptionForHR((int)hr); } } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(new SearchCondition(result)); }