Exemplo n.º 1
0
        /// <summary>
        /// Gets the entity definition for the given type, or null if not found.
        /// </summary>
        /// <param name="cancellationToken">The token used for cancelling this operation.</param>
        /// <returns>Returns the entity definition if found, or null otherwise.</returns>
        public static Task <EntityDefinition> GetEntityDefinition <Tentity>(this IEntityDefinitionProvider provider, CancellationToken cancellationToken)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            return(provider.GetEntityDefinition(typeof(Tentity), cancellationToken));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public T MapItem <T>(ReflectedEntityKey key, EntityFetchExpression fetchExpression, IDataReader dataReader)
            where T : IEntity
        {
            IEntityDefinition definition = _entityDefinitionProvider.GetEntityDefinition(key);
            T entity = (T)definition.GenerateEntity();
            IReadOnlyList <IFieldDefinition> fields = fetchExpression.Fields(_entityDefinitionProvider);

            for (var i = 0; i < fields.Count; i++)
            {
                ReflectionFieldDefinition fieldDefinition = (ReflectionFieldDefinition)fields[i];
                Field field          = fieldDefinition.GetField(entity);
                var   valueConverter = Converter(fieldDefinition);
                field.Value = valueConverter(dataReader.GetValue(i));
            }
            return(default(T));
        }
 public void appendTo(StringBuilder sb, IEntityDefinitionProvider definitionProvider)
 {
     _entityDefinition = definitionProvider.GetEntityDefinition(_baseEntityKey);
     sb.Append(Visit(_expression));
 }
 protected virtual IEnumerable <IFieldDefinition> EvaluateFields(
     IEntityDefinitionProvider entityDefinitionProvider)
 {
     return(EvaluateFields(entityDefinitionProvider.GetEntityDefinition(EntityKey)));
 }