private static void ValidateMaxLength(int maxLength) { if (maxLength <= 0) { throw EntityUtil.ArgumentOutOfRange(System.Data.Entity.Strings.InvalidMaxLengthSize, "maxLength"); } }
/// <summary> /// Ensures that sequential access rules are being obeyed for array offset /// getter methods, throws the appropriate exception if not. Also ensures /// that the last column and array offset is set appropriately. /// </summary> /// <param name="ordinal"></param> /// <param name="dataOffset"></param> /// <param name="methodName"></param> private void AssertSequentialAccess(int ordinal, long dataOffset, string methodName) { Debug.Assert(null != _source, "null _source?"); // we should have already called AssertReaderIsOpen. if (ordinal < 0 || ordinal >= _source.ColumnCount) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } if (_lastColumnRead > ordinal || (_lastColumnRead == ordinal && _lastDataOffsetRead == long.MaxValue)) { throw EntityUtil.NonSequentialColumnAccess(ordinal, _lastColumnRead + 1); } if (_lastColumnRead == ordinal) { if (_lastDataOffsetRead >= dataOffset) { throw EntityUtil.NonSequentialArrayOffsetAccess(dataOffset, _lastDataOffsetRead + 1, methodName); } // _lastDataOffsetRead will be set by GetBytes/GetChars, since we need to set it // to the last offset that was actually read, which isn't necessarily what was // requested. } else { // Doin' a new thang... _lastColumnRead = ordinal; _lastDataOffsetRead = -1; } }
private static void ValidateRelationshipRange(int ordinal) { if (unchecked (1u < (uint)ordinal)) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } }
internal StateManagerMemberMetadata Member(int ordinal) { if (unchecked((uint)ordinal < (uint)_members.Length)) { return _members[ordinal]; } throw EntityUtil.ArgumentOutOfRange("ordinal"); }
/// <summary> /// Return the name of the column at the ordinal specified. /// </summary> internal string GetName(int ordinal) { // Some folks are picky about the exception we throw if (ordinal < 0 || ordinal >= RecordStateFactory.ColumnCount) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } return(RecordStateFactory.ColumnNames[ordinal]); }
override public int GetOrdinal(string name) { int ordinal = _cacheEntry.GetOrdinalforCLayerName(name, _metadata); if (ordinal == -1) { throw EntityUtil.ArgumentOutOfRange("name"); } return(ordinal); }
/// <summary> /// Retrieves the ordinal of a field by name /// </summary> /// <param name="name">The name of the field</param> /// <returns>The ordinal of the field</returns> override public int GetOrdinal(string name) { Debug.Assert(_cacheEntry != null, "CacheEntry is required."); int ordinal = _cacheEntry.GetOrdinalforCLayerName(name, _metadata); if (ordinal == -1) { throw EntityUtil.ArgumentOutOfRange("name"); } return(ordinal); }
/// <summary> /// Gets the index relative to this collection for the given index. For an index to really refers to something in /// the base type, the return value is negative relative to this collection. For an index refers to something in this /// collection, the return value is positive. In both cases, it's simply (index) - (base type member count) /// </summary> /// <returns>The relative index</returns> private int GetRelativeIndex(int index) { int baseTypeMemberCount = GetBaseTypeMemberCount(); int thisTypeMemberCount = base.Count; // Check if the index is in range if (index < 0 || index >= baseTypeMemberCount + thisTypeMemberCount) { throw EntityUtil.ArgumentOutOfRange("index"); } return(index - baseTypeMemberCount); }
// --------------- // Public Indexers // --------------- /// <summary> /// This indexer allows callers to retrieve parameters by name. If no /// parameter by the given name exists, an exception is thrown. For /// safe existence-checking, use the Contains method instead. /// </summary> /// <param name="name"> /// The name of the parameter to find. /// </param> /// <returns> /// The parameter object with the specified name. /// </returns> /// <exception cref="ArgumentOutOfRangeException"> /// If no parameter with the specified name is found in the collection. /// </exception> public ObjectParameter this[string name] { get { int index = this.IndexOf(name); if (index == -1) { throw EntityUtil.ArgumentOutOfRange(System.Data.Entity.Strings.ObjectParameterCollection_ParameterNameNotFound(name), "name"); } return(this._parameters[index]); } }
internal EntityKey GetEntityKey(int ordinal) { switch (ordinal) { case 0: return(Key0); case 1: return(Key1); default: throw EntityUtil.ArgumentOutOfRange("ordinal"); } }
/// <summary> /// Used to construct a field metadata object relating a column ordinal and an ImemberMetadata. /// </summary> /// <param name="ordinal">Column oridnal</param> /// <param name="fieldType">Metadata member</param> public FieldMetadata(int ordinal, EdmMember fieldType) { if (ordinal < 0) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } if (null == fieldType) { throw EntityUtil.ArgumentNull("fieldType"); } _fieldType = fieldType; _ordinal = ordinal; }
private string GenerateLocalCacheKey(MergeOption mergeOption, bool useCSharpNullComparisonBehavior) { switch (mergeOption) { case MergeOption.AppendOnly: case MergeOption.NoTracking: case MergeOption.OverwriteChanges: case MergeOption.PreserveChanges: return(string.Join("", Enum.GetName(typeof(MergeOption), mergeOption), useCSharpNullComparisonBehavior)); default: throw EntityUtil.ArgumentOutOfRange("newPlan.MergeOption"); } }
/// <summary> /// Copies the items in this collection to an array /// </summary> /// <param name="array">The array to copy to</param> /// <param name="arrayIndex">The index in the array at which to start the copy</param> /// <exception cref="System.ArgumentNullException">Thrown if array argument is null</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the arrayIndex is less than zero</exception> /// <exception cref="System.ArgumentException">Thrown if the array argument passed in with respect to the arrayIndex passed in not big enough to hold the MetadataCollection being copied</exception> public virtual void CopyTo(T[] array, int arrayIndex) { EntityUtil.GenericCheckArgumentNull(array, "array"); if (arrayIndex < 0) { throw EntityUtil.ArgumentOutOfRange("arrayIndex"); } if (_collectionData.OrderedList.Count > array.Length - arrayIndex) { throw EntityUtil.ArrayTooSmall("arrayIndex"); } _collectionData.OrderedList.CopyTo(array, arrayIndex); }
/// <summary> /// Parse single hex char. /// PRECONDITION - hexChar must be a valid hex digit. /// </summary> private static int HexDigitToBinaryValue(char hexChar) { if (hexChar >= '0' && hexChar <= '9') { return((int)(hexChar - '0')); } if (hexChar >= 'A' && hexChar <= 'F') { return((int)(hexChar - 'A') + 10); } if (hexChar >= 'a' && hexChar <= 'f') { return((int)(hexChar - 'a') + 10); } Debug.Assert(false, "Invalid Hexadecimal Digit"); throw EntityUtil.ArgumentOutOfRange("hexadecimal digit is not valid"); }
/// <summary> /// Ensures that sequential access rules are being obeyed for non-array /// getter methods, throws the appropriate exception if not. Also ensures /// that the last column and array offset is set appropriately. /// </summary> /// <param name="ordinal"></param> private void AssertSequentialAccess(int ordinal) { Debug.Assert(null != _source, "null _source?"); // we should have already called AssertReaderIsOpen. if (ordinal < 0 || ordinal >= _source.ColumnCount) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } if (_lastColumnRead >= ordinal) { throw EntityUtil.NonSequentialColumnAccess(ordinal, _lastColumnRead + 1); } _lastColumnRead = ordinal; // SQLBUDT #442001 -- we need to mark things that are not using GetBytes/GetChars // in a way that prevents them from being read a second time // using those methods. Pointing past any potential data is // how we do that. _lastDataOffsetRead = long.MaxValue; }
/// <summary> /// Helper method to get the edm TypeUsage for the specified column; /// /// If the column requested is a record, we'll pick up whatever the /// current record says it is, otherwise we'll take whatever was stored /// on our record state. /// </summary> /// <param name="ordinal"></param> /// <returns></returns> private TypeUsage GetTypeUsage(int ordinal) { // Some folks are picky about the exception we throw if (ordinal < 0 || ordinal >= _source.ColumnCount) { throw EntityUtil.ArgumentOutOfRange("ordinal"); } TypeUsage result; // RecordState recordState = _source.CurrentColumnValues[ordinal] as RecordState; if (null != recordState) { result = recordState.DataRecordInfo.RecordType; } else { result = _source.GetTypeUsage(ordinal); } return(result); }
// -------------- // Public Methods // -------------- #region Add /// <summary> /// This method adds the specified parameter object to the collection. If /// the parameter object already exists in the collection, an exception is /// thrown. /// </summary> /// <param name="parameter"> /// The parameter object to add to the collection. /// </param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// If the value of the parameter argument is null. /// </exception> /// <exception cref="ArgumentException"> /// If the parameter argument already exists in the collection. This /// behavior differs from that of most collections which allow duplicate /// entries. /// </exception> /// <exception cref="ArgumentException"> /// If another parameter with the same name as the parameter argument /// already exists in the collection. Note that the lookup is case- /// insensitive. This behavior differs from that of most collections, /// and is more like that of a Dictionary. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If the type of the specified parameter is invalid. /// </exception> public void Add(ObjectParameter parameter) { EntityUtil.CheckArgumentNull(parameter, "parameter"); CheckUnlocked(); if (this.Contains(parameter)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameterCollection_ParameterAlreadyExists(parameter.Name), "parameter"); } if (this.Contains(parameter.Name)) { throw EntityUtil.Argument(System.Data.Entity.Strings.ObjectParameterCollection_DuplicateParameterName(parameter.Name), "parameter"); } if (!parameter.ValidateParameterType(this._perspective)) { throw EntityUtil.ArgumentOutOfRange(System.Data.Entity.Strings.ObjectParameter_InvalidParameterType(parameter.ParameterType.FullName), "parameter"); } this._parameters.Add(parameter); this._cacheKey = null; }
/// <summary> /// Copies the items in this collection to an array /// </summary> /// <param name="array">The array to copy to</param> /// <param name="arrayIndex">The index in the array at which to start the copy</param> /// <exception cref="System.ArgumentNullException">Thrown if array argument is null</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the arrayIndex is less than zero</exception> /// <exception cref="System.ArgumentException">Thrown if the array argument passed in with respect to the arrayIndex passed in not big enough to hold the MemberCollection being copied</exception> public override void CopyTo(EdmMember[] array, int arrayIndex) { // Check on the array index if (arrayIndex < 0) { throw EntityUtil.ArgumentOutOfRange("arrayIndex"); } // Check if the array together with the array index has enough room to copy int baseTypeMemberCount = GetBaseTypeMemberCount(); if (base.Count + baseTypeMemberCount > array.Length - arrayIndex) { throw EntityUtil.Argument("arrayIndex"); } // If the base type has any members, copy those first if (baseTypeMemberCount > 0) { ((StructuralType)_declaringType.BaseType).Members.CopyTo(array, arrayIndex); } base.CopyTo(array, arrayIndex + baseTypeMemberCount); }