Ejemplo n.º 1
0
 /// <summary>
 ///     Creates a new <see cref="DependencyInjectionParameterBinding" /> instance for the given service type.
 /// </summary>
 /// <param name="parameterType"> The parameter CLR type. </param>
 /// <param name="serviceType"> The service CLR types, as resolved from dependency injection </param>
 /// <param name="serviceProperty"> The associated <see cref="IServiceProperty" />, or null. </param>
 public DependencyInjectionParameterBinding(
     Type parameterType,
     Type serviceType,
     IPropertyBase?serviceProperty = null)
     : base(parameterType, serviceType, serviceProperty)
 {
 }
Ejemplo n.º 2
0
        public static Expression MakeHasDefaultValue(
            [NotNull] this Expression currentValueExpression,
            [CanBeNull] IPropertyBase?propertyBase)
        {
            if (!currentValueExpression.Type.IsValueType)
            {
                return(Expression.ReferenceEqual(
                           currentValueExpression,
                           Expression.Constant(null, currentValueExpression.Type)));
            }

            if (currentValueExpression.Type.IsGenericType &&
                currentValueExpression.Type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                return(Expression.Not(
                           Expression.Call(
                               currentValueExpression,
                               currentValueExpression.Type.GetRequiredMethod("get_HasValue"))));
            }

            var property = propertyBase as IProperty;
            var clrType  = propertyBase?.ClrType ?? currentValueExpression.Type;
            var comparer = property?.GetValueComparer()
                           ?? ValueComparer.CreateDefault(clrType, favorStructuralComparisons: false);

            return(comparer.ExtractEqualsBody(
                       comparer.Type != clrType
                    ? Expression.Convert(currentValueExpression, comparer.Type)
                    : currentValueExpression,
                       Expression.Default(comparer.Type)));
        }
Ejemplo n.º 3
0
 public DependencyInjectionParameterBinding(
     [NotNull] Type parameterType,
     [NotNull] Type serviceType,
     [CanBeNull] IPropertyBase?serviceProperty = null)
     : base(parameterType, serviceType, serviceProperty)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Creates a new instance of the <see cref="ReaderColumn{T}" /> class.
 /// </summary>
 /// <param name="nullable"> A value indicating if the column is nullable. </param>
 /// <param name="name"> The name of the column. </param>
 /// <param name="property"> The property being read if any, null otherwise. </param>
 /// <param name="getFieldValue"> A function to get field value for the column from the reader. </param>
 public ReaderColumn(
     bool nullable,
     string?name,
     IPropertyBase?property,
     Func <DbDataReader, int[], T> getFieldValue)
     : base(typeof(T), nullable, name, property)
 {
     GetFieldValue = getFieldValue;
 }
Ejemplo n.º 5
0
 public static Expression CreateValueBufferReadValueExpression(
     [NotNull] this Expression valueBuffer,
     [NotNull] Type type,
     int index,
     [CanBeNull] IPropertyBase?property)
 => Expression.Call(
     ValueBufferTryReadValueMethod.MakeGenericMethod(type),
     valueBuffer,
     Expression.Constant(index),
     Expression.Constant(property, typeof(IPropertyBase)));
        /// <summary>
        ///     Creates a new <see cref="DependencyInjectionParameterBinding" /> instance for the given method
        ///     of the given service type.
        /// </summary>
        /// <param name="parameterType"> The parameter CLR type. </param>
        /// <param name="serviceType"> The service CLR types, as resolved from dependency injection </param>
        /// <param name="method"> The method of the service to bind to. </param>
        /// <param name="serviceProperty"> The associated <see cref="IServiceProperty" />, or null. </param>
        public DependencyInjectionMethodParameterBinding(
            Type parameterType,
            Type serviceType,
            MethodInfo method,
            IPropertyBase?serviceProperty = null)
            : base(parameterType, serviceType, serviceProperty)
        {
            Check.NotNull(method, nameof(method));

            Method = method;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override IClrPropertyGetter CreateGeneric <TEntity, TValue, TNonNullableEnumValue>(
            MemberInfo memberInfo,
            IPropertyBase?propertyBase)
        {
            var entityParameter = Expression.Parameter(typeof(TEntity), "entity");

            Expression readExpression;

            if (memberInfo.DeclaringType !.IsAssignableFrom(typeof(TEntity)))
            {
                readExpression = PropertyBase.CreateMemberAccess(propertyBase, entityParameter, memberInfo);
            }
Ejemplo n.º 8
0
        protected ServiceParameterBinding(
            [NotNull] Type parameterType,
            [NotNull] Type serviceType,
            [CanBeNull] IPropertyBase?serviceProperty = null)
            : base(
                parameterType, serviceProperty != null
                    ? new[] { serviceProperty }
                    : Array.Empty <IPropertyBase>())
        {
            Check.NotNull(serviceType, nameof(serviceType));

            ServiceType = serviceType;
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected override IClrPropertySetter CreateGeneric <TEntity, TValue, TNonNullableEnumValue>(
            MemberInfo memberInfo,
            IPropertyBase?propertyBase)
        {
            var entityParameter    = Expression.Parameter(typeof(TEntity), "entity");
            var valueParameter     = Expression.Parameter(typeof(TValue), "value");
            var memberType         = memberInfo.GetMemberType();
            var convertedParameter = memberType == typeof(TValue)
                ? (Expression)valueParameter
                : Expression.Convert(valueParameter, memberType);

            Expression writeExpression;

            if (memberInfo.DeclaringType !.IsAssignableFrom(typeof(TEntity)))
            {
                writeExpression = CreateMemberAssignment(entityParameter);
            }
Ejemplo n.º 10
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected virtual TAccessor Create(MemberInfo memberInfo, IPropertyBase?propertyBase)
        {
            var boundMethod = propertyBase != null
                ? _genericCreate.MakeGenericMethod(
                propertyBase.DeclaringType.ClrType,
                propertyBase.ClrType,
                propertyBase.ClrType.UnwrapNullableType())
                : _genericCreate.MakeGenericMethod(
                memberInfo.DeclaringType !,
                memberInfo.GetMemberType(),
                memberInfo.GetMemberType().UnwrapNullableType());

            try
            {
                return((TAccessor)boundMethod.Invoke(
                           this, new object?[] { memberInfo, propertyBase }) !);
            }
            catch (TargetInvocationException e) when(e.InnerException != null)
            {
                throw e.InnerException;
            }
        }
Ejemplo n.º 11
0
 public ContextParameterBinding(
     [NotNull] Type contextType,
     [CanBeNull] IPropertyBase?serviceProperty = null)
     : base(contextType, contextType, serviceProperty)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 protected abstract TAccessor CreateGeneric <TEntity, TValue, TNonNullableEnumValue>(
     MemberInfo memberInfo,
     IPropertyBase?propertyBase)
     where TEntity : class;
 public EntityTypeParameterBinding([CanBeNull] IPropertyBase?serviceProperty = null)
     : base(typeof(IEntityType), typeof(IEntityType), serviceProperty)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 ///     Creates a new <see cref="ServiceParameterBinding" /> instance for the given service type.
 /// </summary>
 /// <param name="contextType"> The <see cref="DbContext" /> CLR type. </param>
 /// <param name="serviceProperty"> The associated <see cref="IServiceProperty" />, or <see langword="null" />. </param>
 public ContextParameterBinding(
     Type contextType,
     IPropertyBase?serviceProperty = null)
     : base(contextType, contextType, serviceProperty)
 {
 }