private static T FindFirstMatchingObject <T>(QueryFilter filter, bool includeAccountForestRootOrg, bool includeResourceForest, bool useGC, ConsistencyMode consistencyMode, bool useRecipientSession, bool includeSoftDeletedObject, bool includeSecondaryPartitions) where T : ADObject, new()
        {
            IEnumerable <ADSessionSettings> enumerable = PartitionDataAggregator.CreateSessionSettingsCollection(includeAccountForestRootOrg, includeResourceForest, includeSecondaryPartitions);

            foreach (ADSessionSettings adsessionSettings in enumerable)
            {
                if (includeSoftDeletedObject)
                {
                    adsessionSettings.IncludeSoftDeletedObjects = true;
                }
                IDirectorySession directorySession = PartitionDataAggregator.GetDirectorySession(consistencyMode, useRecipientSession, adsessionSettings);
                directorySession.UseGlobalCatalog = useGC;
                T[] array = directorySession.Find <T>(null, QueryScope.SubTree, filter, null, 1);
                if (array != null && array.Length != 0)
                {
                    return(array[0]);
                }
            }
            return(default(T));
        }