ExpressionBindings.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / CommandTrees / ExpressionBindings.cs / 2 / ExpressionBindings.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
 
using System;
using System.Collections.Generic; 
using System.Diagnostics;

using System.Data.Common;
using System.Data.Common.Utils; 
using System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees.Internal; 
 
namespace System.Data.Common.CommandTrees
{ 
    /// 
    /// Describes a binding for an expression. Conceptually similar to a foreach loop
    /// in C#. The DbExpression property defines the collection being iterated over,
    /// while the Var property provides a means to reference the current element 
    /// of the collection during the iteration. DbExpressionBinding is used to describe the set arguments
    /// to relational expressions such as ,  
    /// and . 
    /// 
    ///  
    /// 
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
    public sealed class DbExpressionBinding
    { 
        private ExpressionLink _expr;
        private string _varName; 
        private TypeUsage _varType; 

        internal DbExpressionBinding(DbCommandTree cmdTree, DbExpression input, string varName) 
        {
            //
            // Ensure no argument is null
            // 
            EntityUtil.CheckArgumentNull(varName, "varName");
            _expr = new ExpressionLink("Expression", cmdTree, input); 
 
            //
            // Ensure Variable name is non-empty 
            //
            if (string.IsNullOrEmpty(varName))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_VariableNameNotValid, "varName"); 
            }
 
            // 
            // Ensure the DbExpression has a collection result type
            // 
            TypeUsage elementType = null;
            if(!TypeHelpers.TryGetCollectionElementType(input.ResultType, out elementType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_CollectionRequired, "input"); 
            }
 
            Debug.Assert(elementType.IsReadOnly, "DbExpressionBinding Expression ResultType has editable element type"); 

            _varName = varName; 
            _varType = elementType;
        }

        ///  
        /// Gets or sets the  that defines the input set.
        ///  
        /// The expression is null 
        /// 
        ///     The expression is not associated with the binding's command tree, or its result type is not 
        ///     equal or promotable to the result type of the current value of the property.
        /// 
        public DbExpression Expression { get { return _expr.Expression; } /*CQT_PUBLIC_API(*/internal/*)*/ set { _expr.Expression = value; } }
 
        /// 
        /// Gets the name assigned to the element variable. 
        ///  
        public string VariableName { get { return _varName; } }
 
        /// 
        /// Gets the type metadata of the element variable.
        /// 
        public TypeUsage VariableType { get { return _varType; } } 

        ///  
        /// Creates a new  that references the element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression Variable { get { return _expr.Expression.CommandTree.CreateVariableReferenceExpression(_varName, _varType); } } 

        internal static void Check(string strName, DbExpressionBinding binding, DbCommandTree owner)
        {
            if (null == binding) 
            {
                throw EntityUtil.ArgumentNull(strName); 
            } 

            if (owner != binding.Expression.CommandTree) 
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_TreeMismatch, strName);
            }
        } 
    }
 
    ///  
    /// Defines the binding for the input set to a .
    /// In addition to the properties of , DbGroupExpressionBinding 
    /// also provides access to the group element via the  variable reference.
    /// 
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
    public sealed class DbGroupExpressionBinding 
    {
        private ExpressionLink _expr; 
        private string _varName; 
        private TypeUsage _varType;
        private string _groupVarName; 

        internal DbGroupExpressionBinding(DbCommandTree cmdTree, DbExpression input, string varName, string groupVarName)
        {
            // 
            // Ensure no argument is null
            // 
            EntityUtil.CheckArgumentNull(varName, "varName"); 
            EntityUtil.CheckArgumentNull(groupVarName, "groupVarName");
            _expr = new ExpressionLink("Expression", cmdTree, input); 

            //
            // Ensure Variable and Group names are both non-empty
            // 
            if (string.IsNullOrEmpty(varName))
            { 
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_VariableNameNotValid, "varName"); 
            }
 
            if (string.IsNullOrEmpty(groupVarName))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_GroupBinding_GroupVariableNameNotValid, "groupVarName");
            } 

            // 
            // Ensure the DbExpression has a collection result type 
            //
            TypeUsage elementType = null; 
            if (!TypeHelpers.TryGetCollectionElementType(input.ResultType, out elementType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_GroupBinding_CollectionRequired, "input");
            } 

            Debug.Assert((elementType.IsReadOnly), "DbGroupExpressionBinding Expression ResultType has editable element type"); 
 
            _varName = varName;
            _varType = elementType; 
            _groupVarName = groupVarName;
        }

        ///  
        /// Gets or sets the  that defines the input set.
        ///  
        /// The expression is null 
        /// 
        ///     The expression is not associated with the binding's command tree, or its result type is not 
        ///     equal or promotable to the result type of the current value of the property.
        /// 
        public DbExpression Expression { get { return _expr.Expression; } /*CQT_PUBLIC_API(*/internal/*)*/ set { _expr.Expression = value; } }
 
        /// 
        /// Gets the name assigned to the element variable. 
        ///  
        public string VariableName { get { return _varName; } }
 
        /// 
        /// Gets the type metadata of the element variable.
        /// 
        public TypeUsage VariableType { get { return _varType; } } 

        ///  
        /// Creates a new DbVariableReferenceExpression that references the element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression Variable { get { return _expr.Expression.CommandTree.CreateVariableReferenceExpression(_varName, _varType); } } 

        /// 
        /// Gets the name assigned to the group element variable.
        ///  
        public string GroupVariableName { get { return _groupVarName; } }
 
        ///  
        /// Gets the type metadata of the group element variable.
        ///  
        public TypeUsage GroupVariableType { get { return _varType; } }

        /// 
        /// Creates a new DbVariableReferenceExpression that references the group element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression GroupVariable { get { return this.Expression.CommandTree.CreateVariableReferenceExpression(_groupVarName, _varType); } } 
 
        internal static void Check(string strName, DbGroupExpressionBinding binding, DbCommandTree owner)
        { 
            if (null == binding)
            {
                throw EntityUtil.ArgumentNull(strName);
            } 

            if (owner != binding.Expression.CommandTree) 
            { 
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_TreeMismatch, strName);
            } 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
 
using System;
using System.Collections.Generic; 
using System.Diagnostics;

using System.Data.Common;
using System.Data.Common.Utils; 
using System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees.Internal; 
 
namespace System.Data.Common.CommandTrees
{ 
    /// 
    /// Describes a binding for an expression. Conceptually similar to a foreach loop
    /// in C#. The DbExpression property defines the collection being iterated over,
    /// while the Var property provides a means to reference the current element 
    /// of the collection during the iteration. DbExpressionBinding is used to describe the set arguments
    /// to relational expressions such as ,  
    /// and . 
    /// 
    ///  
    /// 
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
    public sealed class DbExpressionBinding
    { 
        private ExpressionLink _expr;
        private string _varName; 
        private TypeUsage _varType; 

        internal DbExpressionBinding(DbCommandTree cmdTree, DbExpression input, string varName) 
        {
            //
            // Ensure no argument is null
            // 
            EntityUtil.CheckArgumentNull(varName, "varName");
            _expr = new ExpressionLink("Expression", cmdTree, input); 
 
            //
            // Ensure Variable name is non-empty 
            //
            if (string.IsNullOrEmpty(varName))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_VariableNameNotValid, "varName"); 
            }
 
            // 
            // Ensure the DbExpression has a collection result type
            // 
            TypeUsage elementType = null;
            if(!TypeHelpers.TryGetCollectionElementType(input.ResultType, out elementType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_CollectionRequired, "input"); 
            }
 
            Debug.Assert(elementType.IsReadOnly, "DbExpressionBinding Expression ResultType has editable element type"); 

            _varName = varName; 
            _varType = elementType;
        }

        ///  
        /// Gets or sets the  that defines the input set.
        ///  
        /// The expression is null 
        /// 
        ///     The expression is not associated with the binding's command tree, or its result type is not 
        ///     equal or promotable to the result type of the current value of the property.
        /// 
        public DbExpression Expression { get { return _expr.Expression; } /*CQT_PUBLIC_API(*/internal/*)*/ set { _expr.Expression = value; } }
 
        /// 
        /// Gets the name assigned to the element variable. 
        ///  
        public string VariableName { get { return _varName; } }
 
        /// 
        /// Gets the type metadata of the element variable.
        /// 
        public TypeUsage VariableType { get { return _varType; } } 

        ///  
        /// Creates a new  that references the element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression Variable { get { return _expr.Expression.CommandTree.CreateVariableReferenceExpression(_varName, _varType); } } 

        internal static void Check(string strName, DbExpressionBinding binding, DbCommandTree owner)
        {
            if (null == binding) 
            {
                throw EntityUtil.ArgumentNull(strName); 
            } 

            if (owner != binding.Expression.CommandTree) 
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_TreeMismatch, strName);
            }
        } 
    }
 
    ///  
    /// Defines the binding for the input set to a .
    /// In addition to the properties of , DbGroupExpressionBinding 
    /// also provides access to the group element via the  variable reference.
    /// 
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
    public sealed class DbGroupExpressionBinding 
    {
        private ExpressionLink _expr; 
        private string _varName; 
        private TypeUsage _varType;
        private string _groupVarName; 

        internal DbGroupExpressionBinding(DbCommandTree cmdTree, DbExpression input, string varName, string groupVarName)
        {
            // 
            // Ensure no argument is null
            // 
            EntityUtil.CheckArgumentNull(varName, "varName"); 
            EntityUtil.CheckArgumentNull(groupVarName, "groupVarName");
            _expr = new ExpressionLink("Expression", cmdTree, input); 

            //
            // Ensure Variable and Group names are both non-empty
            // 
            if (string.IsNullOrEmpty(varName))
            { 
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Binding_VariableNameNotValid, "varName"); 
            }
 
            if (string.IsNullOrEmpty(groupVarName))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_GroupBinding_GroupVariableNameNotValid, "groupVarName");
            } 

            // 
            // Ensure the DbExpression has a collection result type 
            //
            TypeUsage elementType = null; 
            if (!TypeHelpers.TryGetCollectionElementType(input.ResultType, out elementType))
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_GroupBinding_CollectionRequired, "input");
            } 

            Debug.Assert((elementType.IsReadOnly), "DbGroupExpressionBinding Expression ResultType has editable element type"); 
 
            _varName = varName;
            _varType = elementType; 
            _groupVarName = groupVarName;
        }

        ///  
        /// Gets or sets the  that defines the input set.
        ///  
        /// The expression is null 
        /// 
        ///     The expression is not associated with the binding's command tree, or its result type is not 
        ///     equal or promotable to the result type of the current value of the property.
        /// 
        public DbExpression Expression { get { return _expr.Expression; } /*CQT_PUBLIC_API(*/internal/*)*/ set { _expr.Expression = value; } }
 
        /// 
        /// Gets the name assigned to the element variable. 
        ///  
        public string VariableName { get { return _varName; } }
 
        /// 
        /// Gets the type metadata of the element variable.
        /// 
        public TypeUsage VariableType { get { return _varType; } } 

        ///  
        /// Creates a new DbVariableReferenceExpression that references the element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression Variable { get { return _expr.Expression.CommandTree.CreateVariableReferenceExpression(_varName, _varType); } } 

        /// 
        /// Gets the name assigned to the group element variable.
        ///  
        public string GroupVariableName { get { return _groupVarName; } }
 
        ///  
        /// Gets the type metadata of the group element variable.
        ///  
        public TypeUsage GroupVariableType { get { return _varType; } }

        /// 
        /// Creates a new DbVariableReferenceExpression that references the group element variable. 
        /// 
        /*CQT_PUBLIC_API(*/internal/*)*/ DbVariableReferenceExpression GroupVariable { get { return this.Expression.CommandTree.CreateVariableReferenceExpression(_groupVarName, _varType); } } 
 
        internal static void Check(string strName, DbGroupExpressionBinding binding, DbCommandTree owner)
        { 
            if (null == binding)
            {
                throw EntityUtil.ArgumentNull(strName);
            } 

            if (owner != binding.Expression.CommandTree) 
            { 
                throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_General_TreeMismatch, strName);
            } 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK