using System.Linq; using System.Reflection; using Abp.Domain.Entities; using Abp.Extensions; namespace Abp.MultiTenancy { internal class MultiTenancyHelper { public static bool IsMultiTenantEntity(object entity) { return entity is IMayHaveTenant || entity is IMustHaveTenant; } /// The entity to check /// TenantId or null for host public static bool IsTenantEntity(object entity, int? expectedTenantId) { return (entity is IMayHaveTenant && entity.As().TenantId == expectedTenantId) || (entity is IMustHaveTenant && entity.As().TenantId == expectedTenantId); } public static bool IsHostEntity(object entity) { MultiTenancySideAttribute attribute = entity.GetType().GetTypeInfo() .GetCustomAttributes(typeof(MultiTenancySideAttribute), true) .Cast() .FirstOrDefault(); if (attribute == null) { return false; } return attribute.Side.HasFlag(MultiTenancySides.Host); } } }