示例#1
0
        /// <summary>
        /// Gets the entity definition for the given type from the provider, or throws if not found.
        /// (Can be used for ensuring no null is returned.)
        /// </summary>
        /// <param name="provider">The provider to get entity definitions from.</param>
        /// <param name="entityType">The type of the entity to get definition for.</param>
        /// <param name="cancellationToken">The token used for cancelling this operation.</param>
        /// <returns>Returns the non-null entity definition if found, or throws an exception.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="provider"/> or <paramref name="entityType"/> is null.</exception>
        /// <exception cref="NullReferenceException">Thrown if <paramref name="provider"/> returns null.</exception>
        public static async Task <EntityDefinition> GetEntityDefinitionOrThrow(this IEntityDefinitionProvider provider, Type entityType, CancellationToken cancellationToken)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var entityDefinition = await provider.GetEntityDefinition(entityType, cancellationToken).ConfigureAwait(false);

            if (entityDefinition == null)
            {
                throw new NullReferenceException($"Entity definition provider of type '{provider.GetType().FullName}' could not get entity for type '{entityType.FullName}'.");
            }

            return(entityDefinition);
        }