Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Objects / ObjectParameter.cs / 2 / ObjectParameter.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupowner [....] //--------------------------------------------------------------------- using System; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.Common.CommandTrees; using System.Data.Metadata.Edm; using System.Diagnostics; namespace System.Data.Objects { ////// This class represents a query parameter at the object layer, which consists /// of a Name, a Type and a Value. /// public sealed class ObjectParameter { #region Static Methods // -------------- // Static Methods // -------------- #region ValidateParameterName ////// This internal method uses regular expression matching to ensure that the /// specified parameter name is valid. Parameter names must start with a letter, /// and may only contain letters (A-Z, a-z), numbers (0-9) and underscores (_). /// internal static bool ValidateParameterName (string name) { // Note: Parameter names must begin with a letter, and may contain only // letters, numbers and underscores. return DbCommandTree.IsValidParameterName(name); } #endregion #endregion #region Public Constructors // ------------------- // Public Constructors // ------------------- #region ObjectParameter (string, Type) ////// This constructor creates an unbound (i.e., value-less) parameter from the /// specified name and type. The value can be set at any time through the /// public 'Value' property. /// /// /// The parameter name. /// /// /// The CLR type of the parameter. /// ////// A new unbound ObjectParameter instance. /// ////// If the value of either argument is null. /// ////// If the value of the name argument is invalid. Parameter names must start /// with a letter and may only contain letters (A-Z, a-z), numbers (0-9) and /// underscores (_). /// public ObjectParameter (string name, Type type) { EntityUtil.CheckArgumentNull(name, "name"); EntityUtil.CheckArgumentNull(type, "type"); if (!ObjectParameter.ValidateParameterName(name)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameter_InvalidParameterName(name), "name"); } this._name = name; this._type = type; // If the parameter type is Nullable<>, we need to extract out the underlying // Nullable<> type argument. this.FindMappableType(this._type); } #endregion #region ObjectParameter (string, object) ////// This constructor creates a fully-bound (i.e., valued) parameter from the /// specified name and value. The type is inferred from the initial value, but /// the value can be changed at any time through the public 'Value' property. /// /// /// The parameter name. /// /// /// The initial value (and inherently, type) of the parameter. /// ////// A new fully-bound ObjectParameter instance. /// ////// If the value of either argument is null. /// ////// If the value of the name argument is invalid. Parameter names must start /// with a letter and may only contain letters (A-Z, a-z), numbers (0-9) and /// underscores (_). /// public ObjectParameter (string name, object value) { EntityUtil.CheckArgumentNull(name, "name"); EntityUtil.CheckArgumentNull(value, "value"); if (!ObjectParameter.ValidateParameterName(name)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameter_InvalidParameterName(name), "name"); } this._name = name; this._type = value.GetType(); this._value = value; // If the parameter type is Nullable<>, we need to extract out the underlying // Nullable<> type argument. this.FindMappableType(this._type); } #endregion #endregion #region Private Constructors // ------------------- // Copy Constructor // ------------------- ////// This constructor is used by /// /// The existing ObjectParameter instance from which field values should be taken. /// ///to create a new ObjectParameter /// with field values taken from the field values of an existing ObjectParameter. /// /// A new ObjectParameter instance with the same field values as the specified ObjectParameter /// private ObjectParameter(ObjectParameter template) { Debug.Assert(template != null, "Template ObjectParameter cannot be null"); this._name = template._name; this._type = template._type; this._mappableType = template._mappableType; this._effectiveType = template._effectiveType; this._value = template._value; } #endregion #region Private Fields // -------------- // Private Fields // -------------- ////// The name of the parameter. Cannot be null and is immutable. /// private string _name; ////// The CLR type of the parameter. Cannot be null and is immutable. /// private Type _type; ////// The mappable CLR type of the parameter. Unless the parameter type is /// Nullable, this type is equal to the parameter type. In the case of /// Nullable parameters, this type is the underlying Nullable argument /// type. Cannot be null and is immutable. /// private Type _mappableType; ////// Used to specify the exact metadata type of this parameter. /// Typically null, can only be set using the internal private TypeUsage _effectiveType; ///property. /// /// The value of the parameter. Does not need to be bound until execution /// time and can be modified at any time. /// private object _value; #endregion #region Public Properties // ----------------- // Public Properties // ----------------- ////// The parameter name, which can only be set through a constructor. /// public string Name { get { return this._name; } } ////// The parameter type, which can only be set through a constructor. /// public Type ParameterType { get { return this._type; } } ////// The parameter value, which can be set at any time (and subsequently /// changed) before query execution. Note that type-checking is not /// enforced between the declared parameter type and the type of the /// specified value; such validation is left up to the underlying /// provider(s) at execution time. /// public object Value { get { return this._value; } set { this._value = value; } } #endregion #region Internal Properties // ------------------- // Internal Properties // ------------------- ////// Gets or sets a internal TypeUsage TypeUsage { get { return _effectiveType; } set { Debug.Assert(null == _effectiveType, "Effective type should only be set once"); _effectiveType = value; } } ///that specifies the exact /// type of which the parameter value is considered an instance. /// /// The mappable parameter type; this is primarily used to handle the case of /// Nullable parameter types. For example, metadata knows nothing about 'int?', /// only 'Int32'. For internal use only. /// internal Type MappableType { get { return this._mappableType; } } #endregion #region Internal Methods // ---------------- // Internal Methods // ---------------- ////// Creates a new ObjectParameter instance with identical field values to this instance. /// ///The new ObjectParameter instance internal ObjectParameter ShallowCopy() { return new ObjectParameter(this); } ////// This internal method ensures that the specified type is a scalar /// type supported by the underlying provider by ensuring that scalar /// metadata for this type is retrievable. /// internal bool ValidateParameterType (ClrPerspective perspective) { TypeUsage type = null; // The parameter type metadata is only valid if it's scalar or enumeration type metadata. if ((perspective.TryGetType(this._mappableType, out type)) && (TypeSemantics.IsPrimitiveType(type) || TypeSemantics.IsEnumerationType(type))) { return true; } return false; } #endregion #region Private Methods // --------------- // Private Methods // --------------- #region FindMappableType ////// This private method determines the metadata-mappable type of the parameter. /// For instance, for Int16? the mappable type is Int16. For enumerations, the /// mappable type is Int32, etc. /// private void FindMappableType (Type type) { // By default, set the underlying type of the generic to be the input type. this._mappableType = type; // If this is a nullable type, extract and return the underlying type of // the generic. if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable<>))) { this._mappableType = type.GetGenericArguments()[0]; } } #endregion #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupowner [....] //--------------------------------------------------------------------- using System; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.Common.CommandTrees; using System.Data.Metadata.Edm; using System.Diagnostics; namespace System.Data.Objects { ////// This class represents a query parameter at the object layer, which consists /// of a Name, a Type and a Value. /// public sealed class ObjectParameter { #region Static Methods // -------------- // Static Methods // -------------- #region ValidateParameterName ////// This internal method uses regular expression matching to ensure that the /// specified parameter name is valid. Parameter names must start with a letter, /// and may only contain letters (A-Z, a-z), numbers (0-9) and underscores (_). /// internal static bool ValidateParameterName (string name) { // Note: Parameter names must begin with a letter, and may contain only // letters, numbers and underscores. return DbCommandTree.IsValidParameterName(name); } #endregion #endregion #region Public Constructors // ------------------- // Public Constructors // ------------------- #region ObjectParameter (string, Type) ////// This constructor creates an unbound (i.e., value-less) parameter from the /// specified name and type. The value can be set at any time through the /// public 'Value' property. /// /// /// The parameter name. /// /// /// The CLR type of the parameter. /// ////// A new unbound ObjectParameter instance. /// ////// If the value of either argument is null. /// ////// If the value of the name argument is invalid. Parameter names must start /// with a letter and may only contain letters (A-Z, a-z), numbers (0-9) and /// underscores (_). /// public ObjectParameter (string name, Type type) { EntityUtil.CheckArgumentNull(name, "name"); EntityUtil.CheckArgumentNull(type, "type"); if (!ObjectParameter.ValidateParameterName(name)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameter_InvalidParameterName(name), "name"); } this._name = name; this._type = type; // If the parameter type is Nullable<>, we need to extract out the underlying // Nullable<> type argument. this.FindMappableType(this._type); } #endregion #region ObjectParameter (string, object) ////// This constructor creates a fully-bound (i.e., valued) parameter from the /// specified name and value. The type is inferred from the initial value, but /// the value can be changed at any time through the public 'Value' property. /// /// /// The parameter name. /// /// /// The initial value (and inherently, type) of the parameter. /// ////// A new fully-bound ObjectParameter instance. /// ////// If the value of either argument is null. /// ////// If the value of the name argument is invalid. Parameter names must start /// with a letter and may only contain letters (A-Z, a-z), numbers (0-9) and /// underscores (_). /// public ObjectParameter (string name, object value) { EntityUtil.CheckArgumentNull(name, "name"); EntityUtil.CheckArgumentNull(value, "value"); if (!ObjectParameter.ValidateParameterName(name)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameter_InvalidParameterName(name), "name"); } this._name = name; this._type = value.GetType(); this._value = value; // If the parameter type is Nullable<>, we need to extract out the underlying // Nullable<> type argument. this.FindMappableType(this._type); } #endregion #endregion #region Private Constructors // ------------------- // Copy Constructor // ------------------- ////// This constructor is used by /// /// The existing ObjectParameter instance from which field values should be taken. /// ///to create a new ObjectParameter /// with field values taken from the field values of an existing ObjectParameter. /// /// A new ObjectParameter instance with the same field values as the specified ObjectParameter /// private ObjectParameter(ObjectParameter template) { Debug.Assert(template != null, "Template ObjectParameter cannot be null"); this._name = template._name; this._type = template._type; this._mappableType = template._mappableType; this._effectiveType = template._effectiveType; this._value = template._value; } #endregion #region Private Fields // -------------- // Private Fields // -------------- ////// The name of the parameter. Cannot be null and is immutable. /// private string _name; ////// The CLR type of the parameter. Cannot be null and is immutable. /// private Type _type; ////// The mappable CLR type of the parameter. Unless the parameter type is /// Nullable, this type is equal to the parameter type. In the case of /// Nullable parameters, this type is the underlying Nullable argument /// type. Cannot be null and is immutable. /// private Type _mappableType; ////// Used to specify the exact metadata type of this parameter. /// Typically null, can only be set using the internal private TypeUsage _effectiveType; ///property. /// /// The value of the parameter. Does not need to be bound until execution /// time and can be modified at any time. /// private object _value; #endregion #region Public Properties // ----------------- // Public Properties // ----------------- ////// The parameter name, which can only be set through a constructor. /// public string Name { get { return this._name; } } ////// The parameter type, which can only be set through a constructor. /// public Type ParameterType { get { return this._type; } } ////// The parameter value, which can be set at any time (and subsequently /// changed) before query execution. Note that type-checking is not /// enforced between the declared parameter type and the type of the /// specified value; such validation is left up to the underlying /// provider(s) at execution time. /// public object Value { get { return this._value; } set { this._value = value; } } #endregion #region Internal Properties // ------------------- // Internal Properties // ------------------- ////// Gets or sets a internal TypeUsage TypeUsage { get { return _effectiveType; } set { Debug.Assert(null == _effectiveType, "Effective type should only be set once"); _effectiveType = value; } } ///that specifies the exact /// type of which the parameter value is considered an instance. /// /// The mappable parameter type; this is primarily used to handle the case of /// Nullable parameter types. For example, metadata knows nothing about 'int?', /// only 'Int32'. For internal use only. /// internal Type MappableType { get { return this._mappableType; } } #endregion #region Internal Methods // ---------------- // Internal Methods // ---------------- ////// Creates a new ObjectParameter instance with identical field values to this instance. /// ///The new ObjectParameter instance internal ObjectParameter ShallowCopy() { return new ObjectParameter(this); } ////// This internal method ensures that the specified type is a scalar /// type supported by the underlying provider by ensuring that scalar /// metadata for this type is retrievable. /// internal bool ValidateParameterType (ClrPerspective perspective) { TypeUsage type = null; // The parameter type metadata is only valid if it's scalar or enumeration type metadata. if ((perspective.TryGetType(this._mappableType, out type)) && (TypeSemantics.IsPrimitiveType(type) || TypeSemantics.IsEnumerationType(type))) { return true; } return false; } #endregion #region Private Methods // --------------- // Private Methods // --------------- #region FindMappableType ////// This private method determines the metadata-mappable type of the parameter. /// For instance, for Int16? the mappable type is Int16. For enumerations, the /// mappable type is Int32, etc. /// private void FindMappableType (Type type) { // By default, set the underlying type of the generic to be the input type. this._mappableType = type; // If this is a nullable type, extract and return the underlying type of // the generic. if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable<>))) { this._mappableType = type.GetGenericArguments()[0]; } } #endregion #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CorrelationService.cs
- Attributes.cs
- PointKeyFrameCollection.cs
- HttpRuntime.cs
- SecuritySessionSecurityTokenAuthenticator.cs
- DefaultEventAttribute.cs
- BufferCache.cs
- XmlDocumentFragment.cs
- QilInvoke.cs
- ConfigurationErrorsException.cs
- ActiveXMessageFormatter.cs
- _SslSessionsCache.cs
- PartialCachingControl.cs
- smtppermission.cs
- WebErrorHandler.cs
- InstanceKeyNotReadyException.cs
- RemoteDebugger.cs
- GradientBrush.cs
- DataTemplateKey.cs
- EmptyCollection.cs
- GcSettings.cs
- InternalBase.cs
- Vector3DKeyFrameCollection.cs
- DataContractFormatAttribute.cs
- CustomAttributeFormatException.cs
- Volatile.cs
- ReceiveMessageRecord.cs
- StopStoryboard.cs
- ServerIdentity.cs
- COM2IDispatchConverter.cs
- WebPartVerbsEventArgs.cs
- ConfigurationFileMap.cs
- SiteMapNode.cs
- _UriTypeConverter.cs
- LinkLabel.cs
- ConfigurationManagerHelper.cs
- CodeFieldReferenceExpression.cs
- InplaceBitmapMetadataWriter.cs
- EntityDataSource.cs
- WebPartDisplayModeCollection.cs
- Utilities.cs
- HtmlInputText.cs
- SqlLiftWhereClauses.cs
- DataGridViewSelectedCellCollection.cs
- WeakReferenceEnumerator.cs
- ComUdtElement.cs
- CodeDOMUtility.cs
- DataReaderContainer.cs
- MembershipUser.cs
- WindowInteractionStateTracker.cs
- Margins.cs
- TrailingSpaceComparer.cs
- XmlStreamStore.cs
- IsolatedStorageException.cs
- TraceContext.cs
- NameNode.cs
- ScopeElement.cs
- FilterableAttribute.cs
- MenuItem.cs
- CircleHotSpot.cs
- ReservationCollection.cs
- COM2IDispatchConverter.cs
- ThemeableAttribute.cs
- DataGridViewCellFormattingEventArgs.cs
- KeyValueConfigurationElement.cs
- PixelFormat.cs
- dtdvalidator.cs
- SwitchLevelAttribute.cs
- DataServiceException.cs
- SymLanguageVendor.cs
- ViewStateException.cs
- UriWriter.cs
- HitTestFilterBehavior.cs
- UdpDiscoveryMessageFilter.cs
- ExpressionBuilder.cs
- ValueType.cs
- FunctionImportElement.cs
- DirectoryNotFoundException.cs
- Label.cs
- ObjectDataProvider.cs
- _StreamFramer.cs
- TableLayoutRowStyleCollection.cs
- Guid.cs
- FilterElement.cs
- CorePropertiesFilter.cs
- Border.cs
- RemotingConfiguration.cs
- TableLayoutStyle.cs
- BindingSource.cs
- InteropBitmapSource.cs
- RecognizerInfo.cs
- ToolStripTextBox.cs
- ApplicationSecurityManager.cs
- ZipIOExtraFieldPaddingElement.cs
- WsiProfilesElementCollection.cs
- TimeSpanSecondsConverter.cs
- UnsafeNativeMethods.cs
- LayoutTableCell.cs
- ResourceDescriptionAttribute.cs
- StreamAsIStream.cs