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;
}