System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateTypeUnary(System.Data.Common.CommandTrees.DbExpression, System.Data.Metadata.Edm.TypeUsage, string)

Here are the examples of the csharp api class System.Data.Common.CommandTrees.ExpressionBuilder.Internal.ArgumentValidation.ValidateTypeUnary(System.Data.Common.CommandTrees.DbExpression, System.Data.Metadata.Edm.TypeUsage, string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

1. Example

View license
internal static void ValidateCastTo(DbExpression argument, TypeUsage toType)
        {
            ValidateTypeUnary(argument, toType, "toType");

            //
            // Verify that the cast is allowed
            //
            if (!TypeSemantics.IsCastAllowed(argument.ResultType, toType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Cast_InvalidCast(TypeHelpers.GetFullName(argument.ResultType), TypeHelpers.GetFullName(toType)));
            }
        }

2. Example

View license
internal static void ValidateTreatAs(DbExpression argument, TypeUsage asType)
        {
            ValidateTypeUnary(argument, asType, "asType");

            //
            // Verify the type to treat as. Treat-As (NullType) is not allowed.
            //
            RequirePolymorphicType(asType, "asType");

            //
            // Verify that the Treat operation is allowed
            //
            if (!TypeSemantics.IsValidPolymorphicCast(argument.ResultType, asType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_PolymorphicArgRequired(typeof(DbTreatExpression).Name));
            }
        }

3. Example

View license
internal static TypeUsage ValidateIsOf(DbExpression argument, TypeUsage type)
        {
            ValidateTypeUnary(argument, type, "type");

            //
            // Ensure the ofType is non-null, associated with the correct metadata workspace/dataspace,
            // is not NullType, and is polymorphic
            //
            RequirePolymorphicType(type, "type");

            //
            // Verify that the IsOf operation is allowed
            //
            if (!TypeSemantics.IsValidPolymorphicCast(argument.ResultType, type))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_PolymorphicArgRequired(typeof(DbIsOfExpression).Name));
            }

            return _booleanType;
        }

4. Example

View license
internal static TypeUsage ValidateOfType(DbExpression argument, TypeUsage type)
        {
            ValidateTypeUnary(argument, type, "type");

            //
            // Ensure that the type is non-null and valid - from the same metadata collection and dataspace and the command tree.
            // The type is also not allowed to be NullType.
            //
            RequirePolymorphicType(type, "type");

            //
            // Ensure that the argument is actually of a collection type.
            //
            RequireCollectionArgument<DbOfTypeExpression>(argument);

            //
            // Verify that the OfType operation is allowed
            //
            TypeUsage elementType = null;
            if (!TypeHelpers.TryGetCollectionElementType(argument.ResultType, out elementType) ||
                !TypeSemantics.IsValidPolymorphicCast(elementType, type))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_PolymorphicArgRequired(typeof(DbOfTypeExpression).Name));
            }

            //
            // The type of this DbExpression is a new collection type based on the requested element type.
            //
            return CreateCollectionResultType(type);
        }