private TResult GetObjectInternal <TStorage, TResult>(Guid tenantId, Guid objectId, bool includeDeletedObjects, Func <TStorage, TResult> convertFunc) where TStorage : UnifiedPolicyStorageBase, new() where TResult : PolicyConfigurationBase
        {
            TResult result = default(TResult);
            ITenantConfigurationSession tenantSession = UnifiedPolicySession.GetTenantSession(tenantId);
            QueryFilter filter   = UnifiedPolicySession.CreateGetObjectQueryFilter(tenantId, objectId, includeDeletedObjects);
            TStorage    tstorage = tenantSession.Find <TStorage>(filter, null, false, null).Cast <TStorage>().FirstOrDefault <TStorage>();

            if (tstorage != null)
            {
                result = convertFunc(tstorage);
            }
            return(result);
        }
        private static void DeleteReferencedObject(ITenantConfigurationSession session, UnifiedPolicySettingStatus deleteStatus)
        {
            IConfigurable configurable = null;
            bool          flag         = false;
            QueryFilter   filter       = UnifiedPolicySession.CreateGetObjectQueryFilter(deleteStatus.OrganizationalUnitRoot.ObjectGuid, deleteStatus.Id.ObjectGuid, true);
            string        settingType;

            if ((settingType = deleteStatus.SettingType) != null)
            {
                if (!(settingType == "AssociationStorage"))
                {
                    if (!(settingType == "BindingStorage"))
                    {
                        if (!(settingType == "PolicyStorage"))
                        {
                            if (!(settingType == "RuleStorage"))
                            {
                                if (!(settingType == "ScopeStorage"))
                                {
                                    goto IL_F7;
                                }
                                configurable = session.Find <ScopeStorage>(filter, null, false, null).FirstOrDefault <IConfigurable>();
                            }
                            else
                            {
                                configurable = session.Find <RuleStorage>(filter, null, false, null).FirstOrDefault <IConfigurable>();
                            }
                        }
                        else
                        {
                            configurable = session.Find <PolicyStorage>(filter, null, false, null).FirstOrDefault <IConfigurable>();
                            flag         = true;
                        }
                    }
                    else
                    {
                        configurable = session.Find <BindingStorage>(filter, null, false, null).FirstOrDefault <IConfigurable>();
                    }
                }
                else
                {
                    configurable = session.Find <AssociationStorage>(filter, null, false, null).FirstOrDefault <IConfigurable>();
                }
                if (flag)
                {
                    IEnumerable <RuleStorage> enumerable = from RuleStorage r in session.Find <RuleStorage>(new ComparisonFilter(ComparisonOperator.Equal, DalHelper.IncludeTombstonesProperty, true), null, false, null)
                                                           where r.ParentPolicyId == deleteStatus.Id.ObjectGuid && r.ObjectState != ObjectState.Deleted
                                                           select r;
                    foreach (RuleStorage instance in enumerable)
                    {
                        session.Delete(instance);
                    }
                    IEnumerable <BindingStorage> enumerable2 = session.Find <BindingStorage>(QueryFilter.AndTogether(new QueryFilter[]
                    {
                        new ComparisonFilter(ComparisonOperator.Equal, UnifiedPolicyStorageBaseSchema.ContainerProp, deleteStatus.Id.ObjectGuid),
                        new ComparisonFilter(ComparisonOperator.Equal, DalHelper.IncludeTombstonesProperty, true)
                    }), null, false, null).Cast <BindingStorage>();
                    foreach (BindingStorage instance2 in enumerable2)
                    {
                        session.Delete(instance2);
                    }
                }
                if (configurable != null && configurable.ObjectState != ObjectState.Deleted)
                {
                    session.Delete(configurable);
                }
                return;
            }
IL_F7:
            throw new NotSupportedException(string.Format("Unable to delete object of type '{0}'", deleteStatus.SettingType ?? "<null>"));
        }