Esempio n. 1
0
        public override void Validate(Type entityType)
        {
            if (Expr1Source == null)
            {
                throw new Exception("Unable to validate 1st expression: " + Expr1Source);
            }

            if (Expr1Source is string expr1SourceString)
            {
                if (expr1SourceString.EndsWith("Id") && entityType.GetProperty(expr1SourceString) == null)
                {
                    var match = _navigationPropertyNameRegex.Match(expr1SourceString);

                    if (match.Success)
                    {
                        expr1SourceString = $"{match.Groups[1].Value}.Id";
                        Expr1Source       = expr1SourceString;
                    }
                }
            }

            _block1 = BaseBlock.CreateLHSBlock(Expr1Source, entityType);

            if (_op == Operator.In && !(Expr2Source is IList))
            {
                throw new Exception("The 'in' operator requires that its right hand argument be an array");
            }

            // Special purpose Enum handling

            var enumType = GetEnumType(_block1);

            if (enumType != null)
            {
                if (Expr2Source != null)
                {
                    var et        = TypeFns.GetNonNullableType(enumType);
                    var expr2Enum = Enum.Parse(et, (string)Expr2Source);
                    _block2 = BaseBlock.CreateRHSBlock(expr2Enum, entityType, null);
                }
                else
                {
                    _block2 = BaseBlock.CreateRHSBlock(null, entityType, null);
                }
            }
            else
            {
                try
                {
                    _block2 = BaseBlock.CreateRHSBlock(Expr2Source, entityType, _block1.DataType);
                }
                catch (Exception)
                {
                    _block2 = BaseBlock.CreateRHSBlock(Expr2Source, entityType, null);
                }
            }
        }
Esempio n. 2
0
        public override void Validate(Type entityType)
        {
            if (Expr1Source == null)
            {
                throw new Exception("Unable to validate 1st expression: " + this.Expr1Source);
            }

            this._block1 = BaseBlock.CreateLHSBlock(Expr1Source, entityType);

            if (_op == Operator.In && !(Expr2Source is IList))
            {
                throw new Exception("The 'in' operator requires that its right hand argument be an array");
            }

            // Special purpose Enum handling

            var enumType = GetEnumType(this._block1);

            if (enumType != null)
            {
                if (Expr2Source != null)
                {
                    var et        = TypeFns.GetNonNullableType(enumType);
                    var expr2Enum = Enum.Parse(et, (string)Expr2Source);
                    this._block2 = BaseBlock.CreateRHSBlock(expr2Enum, entityType, null);
                }
                else
                {
                    this._block2 = BaseBlock.CreateRHSBlock(null, entityType, null);
                }
            }
            else
            {
                try
                {
                    this._block2 = BaseBlock.CreateRHSBlock(Expr2Source, entityType, this._block1.DataType);
                }
                catch (Exception)
                {
                    this._block2 = BaseBlock.CreateRHSBlock(Expr2Source, entityType, null);
                }
            }
        }