internal SearchCondition(ICondition nativeSearchCondition) { NativeSearchCondition = nativeSearchCondition ?? throw new ArgumentNullException(nameof(nativeSearchCondition)); HResult hr = NativeSearchCondition.GetConditionType(out conditionType); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } if (ConditionType == SearchConditionType.Leaf) { using (var propVar = new PropVariant()) { hr = NativeSearchCondition.GetComparisonInfo(out canonicalName, out conditionOperation, propVar); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } PropertyValue = propVar.Value.ToString(); } } }
/// <summary> /// Retrieves an array of the sub-conditions. /// </summary> public IEnumerable <SearchCondition> GetSubConditions() { // Our list that we'll return List <SearchCondition> subConditionsList = new List <SearchCondition>(); // Get the sub-conditions from the native API object subConditionObj; Guid guid = new Guid(ShellIIDGuid.IEnumUnknown); HResult hr = NativeSearchCondition.GetSubConditions(ref guid, out subConditionObj); if (!CoreErrorHelper.Succeeded(hr)) { throw new ShellException(hr); } // Convert each ICondition to SearchCondition if (subConditionObj != null) { IEnumUnknown enumUnknown = subConditionObj as IEnumUnknown; IntPtr buffer = IntPtr.Zero; uint fetched = 0; while (hr == HResult.Ok) { hr = enumUnknown.Next(1, ref buffer, ref fetched); if (hr == HResult.Ok && fetched == 1) { subConditionsList.Add(new SearchCondition((ICondition)Marshal.GetObjectForIUnknown(buffer))); } } } return(subConditionsList); }
/// <summary> /// Retrieves an array of the sub-conditions. /// </summary> public IEnumerable <SearchCondition> GetSubConditions() { // Our list that we'll return var subConditionsList = new List <SearchCondition>(); // Get the sub-conditions from the native API object subConditionObj; var guid = new Guid(InterfaceGuids.IEnumUnknown); HResult hr = NativeSearchCondition.GetSubConditions(ref guid, out subConditionObj); if (hr != HResult.S_OK) { throw new Exception(hr.ToString()); } // Convert each ICondition to SearchCondition if (subConditionObj != null) { var enumUnknown = subConditionObj as IEnumUnknown; IntPtr buffer = IntPtr.Zero; uint fetched = 0; while (hr == HResult.S_OK) { hr = enumUnknown.Next(1, ref buffer, ref fetched); if (hr == HResult.S_OK && fetched == 1) { subConditionsList.Add(new SearchCondition((ICondition)Marshal.GetObjectForIUnknown(buffer))); } } } return(subConditionsList); }