/// <summary> /// Gets the cached primary key property for the entity. /// </summary> /// <typeparam name="TEntity">The type of the target entity.</typeparam> /// <param name="command">The target command.</param> /// <returns>The cached properties of the entity.</returns> public static IEnumerable <ClassProperty> Get <TEntity>(Command command = Command.None) where TEntity : class { var key = $"{typeof(TEntity).FullName}.{command.ToString()}"; var properties = (IEnumerable <ClassProperty>)null; if (m_cache.TryGetValue(key, out properties) == false) { properties = ClassExpression.GetProperties <TEntity>(command); m_cache.TryAdd(key, properties); } return(properties); }
/// <summary> /// Gets the cached primary key property for the entity. /// </summary> /// <typeparam name="TEntity">The type of the target entity.</typeparam> /// <returns>The cached properties of the entity.</returns> public static IEnumerable <ClassProperty> Get <TEntity>() where TEntity : class { var key = typeof(TEntity).FullName; var properties = (IEnumerable <ClassProperty>)null; if (m_cache.TryGetValue(key, out properties) == false) { properties = ClassExpression.GetProperties <TEntity>(); m_cache.TryAdd(key, properties); } return(properties); }
/// <summary> /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity. /// </summary> /// <typeparam name="TEntity">The type of the target entity.</typeparam> /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns> public static IEnumerable <ClassProperty> Get <TEntity>() where TEntity : class { var type = typeof(TEntity); var properties = (IEnumerable <ClassProperty>)null; var key = type.FullName.GetHashCode(); // Try get the value if (type.GetTypeInfo().IsGenericType == false && m_cache.TryGetValue(key, out properties) == false) { properties = ClassExpression.GetProperties <TEntity>(); m_cache.TryAdd(key, properties); } // Return the value return(properties); }
/// <summary> /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity. /// </summary> /// <typeparam name="TEntity">The type of the target entity.</typeparam> /// <param name="dbSetting">The database setting that is currently in used.</param> /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns> public static IEnumerable <ClassProperty> Get <TEntity>(IDbSetting dbSetting) where TEntity : class { var properties = (IEnumerable <ClassProperty>)null; var key = typeof(TEntity).FullName.GetHashCode(); // Add the DbSetting hashcode if (dbSetting != null) { key += dbSetting.GetHashCode(); } // Try get the value if (m_cache.TryGetValue(key, out properties) == false) { properties = ClassExpression.GetProperties <TEntity>(dbSetting); m_cache.TryAdd(key, properties); } // Return the value return(properties); }