Ejemplo n.º 1
0
        private static object CreateFactory(
            Type factoryType,
            IEntityMemberInfo member,
            params object[] args)
        {
            int generics = factoryType.GetGenericArguments().Length;

            switch (generics)
            {
            case 1:
                factoryType = factoryType.MakeGenericType(member.EntityType);
                break;

            case 2:
                factoryType = factoryType.MakeGenericType(member.EntityType, member.MemberType);
                break;

            default:
                throw new InvalidOperationException("Invalid factory type");
            }

            object[] ctorArgs = new object[args.Length + 1];
            ctorArgs[0] = member;
            Array.Copy(args, 0, ctorArgs, 1, args.Length);

            ConstructorInfo ctor = factoryType.GetConstructors().Single();

            return(ctor.Invoke(ctorArgs));
        }
Ejemplo n.º 2
0
        private static object CreateFactory(
            Type factoryType,
            IEntityMemberInfo member,
            params object[] args)
        {
            int generics = factoryType.GetGenericArguments().Length;

            switch (generics)
            {
                case 1:
                    factoryType = factoryType.MakeGenericType(member.EntityType);
                    break;
                case 2:
                    factoryType = factoryType.MakeGenericType(member.EntityType, member.MemberType);
                    break;
                default:
                    throw new InvalidOperationException("Invalid factory type");
            }

            object[] ctorArgs = new object[args.Length + 1];
            ctorArgs[0] = member;
            Array.Copy(args, 0, ctorArgs, 1, args.Length);

            ConstructorInfo ctor = factoryType.GetConstructors().Single();
            return ctor.Invoke(ctorArgs);
        }
Ejemplo n.º 3
0
 public CharLimitConstraintFactory(
     IEntityMemberInfo <TEntity, string> member,
     int maxLength)
     : base(member)
 {
     this.maxLength = maxLength;
 }
Ejemplo n.º 4
0
 public NVarCharConstraint(
     IEntityMemberInfo <TEntity, string> member,
     int maxLength)
     : base(member)
 {
     this.maxLength = maxLength;
 }
        private static Expression <Func <TEntity, TMember> > CreateGetter(IEntityMemberInfo memberInfo)
        {
            ParameterExpression entity = Expression.Parameter(memberInfo.EntityType);

            Expression setterBody = Expression.MakeMemberAccess(entity, memberInfo.Member);

            return(Expression.Lambda <Func <TEntity, TMember> >(setterBody, entity));
        }
        private static Expression <Action <TEntity, TMember> > CreateSetter(IEntityMemberInfo memberInfo)
        {
            ParameterExpression entity = Expression.Parameter(memberInfo.EntityType);
            ParameterExpression value  = Expression.Parameter(memberInfo.MemberType);

            Expression setterBody = Expression.Assign(
                Expression.PropertyOrField(entity, memberInfo.Member.Name),
                value);

            return(Expression.Lambda <Action <TEntity, TMember> >(setterBody, entity, value));
        }
Ejemplo n.º 7
0
        public NumericConstraint(
            IEntityMemberInfo <TEntity, decimal> member,
            int precision,
            int scale)
            : base(member)
        {
            Validate(precision, scale);

            this.allDigits            = precision;
            this.fractionalPartDigits = scale;
            this.threshold            = (long)Math.Pow(10, this.WholePartDigits);
        }
Ejemplo n.º 8
0
        protected ConstraintBase(IEntityMemberInfo <TEntity, TMember> member)
        {
            this.member = member ?? throw new ArgumentNullException("member");

            if (this.member is IEntityMemberInfoServicesProvider <TEntity, TMember> servicesProvider)
            {
                this.memberServices =
                    servicesProvider.EntityMemberInfoServices;
            }

            if (this.memberServices == null)
            {
                this.memberServices =
                    new DefaultEntityMemberInfoServices <TEntity, TMember>(this.member);
            }
        }
Ejemplo n.º 9
0
        private static IEntityMemberInfo CreateEntityMemberInfo(MemberInfo member)
        {
            Type entityType = member.DeclaringType;
            Type memberType = TypeHelper.GetMemberType(member);

            Type memberInfoType = typeof(DefaultEntityMemberInfo <,>)
                                  .MakeGenericType(entityType, memberType);

            IEntityMemberInfo result = Activator.CreateInstance(memberInfoType, member)
                                       as IEntityMemberInfo;

            if (result == null)
            {
                throw new InvalidOperationException("Failed to create member info");
            }

            return(result);
        }
Ejemplo n.º 10
0
 public ConstraintFactoryBase(IEntityMemberInfo <TEntity, TMember> member)
 {
     this.member = member;
 }
Ejemplo n.º 11
0
 public NotNullableConstraint(IEntityMemberInfo <TEntity, TMember> member)
     : base(member)
 {
 }
Ejemplo n.º 12
0
 protected override IConstraint<TEntity> Create(IEntityMemberInfo<TEntity, TMember> member)
 {
     return new NotNullableConstraint<TEntity, TMember>(member);
 }
Ejemplo n.º 13
0
 public GeneratedGuidConstraint(IEntityMemberInfo <TEntity, Guid> member)
     : base(member)
 {
 }
 public DefaultEntityMemberInfoServices(IEntityMemberInfo memberInfo)
 {
     this.setter = CreateSetter(memberInfo).Compile();
     this.getter = CreateGetter(memberInfo).Compile();
 }
Ejemplo n.º 15
0
        private static object Create(Type factory, MemberInfo member, params object[] args)
        {
            IEntityMemberInfo entityMember = CreateEntityMemberInfo(member);

            return(CreateFactory(factory, entityMember, args));
        }
 protected override IConstraint <TEntity> Create(IEntityMemberInfo <TEntity, Guid> member)
 {
     return(new GeneratedGuidConstraint <TEntity>(member));
 }
Ejemplo n.º 17
0
 protected abstract IConstraint <TEntity> Create(IEntityMemberInfo <TEntity, TMember> member);
Ejemplo n.º 18
0
 protected override IConstraint <TEntity> Create(IEntityMemberInfo <TEntity, string> member)
 {
     return(new NCharConstraint <TEntity>(member, this.maxLength));
 }