Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / DataError.cs / 1 / DataError.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data {
using System;
using System.Diagnostics;
///
/// Represents an custom error that can be associated with a .
///
internal sealed class DataError {
private string rowError = String.Empty;
// column-level errors
private int count;
private ColumnError[] errorList;
internal const int initialCapacity = 1;
internal DataError() {
}
internal DataError(string rowError) {
SetText(rowError);
}
internal string Text {
get {
return rowError;
}
set {
SetText(value);
}
}
internal bool HasErrors {
get {
return(rowError.Length != 0 || count != 0);
}
}
//
// this method resets the error to the new value.
//
internal void SetColumnError(DataColumn column, string error) {
Debug.Assert(column != null, "Invalid (null) argument");
Debug.Assert(column.Table != null, "Invalid (loose) column");
if (error == null || error.Length == 0) {
// remove error from the collection
Clear(column);
}
else {
if (errorList == null) {
errorList = new ColumnError[initialCapacity];
}
int i = IndexOf(column);
errorList[i].column = column;
errorList[i].error = error;
column.errors++;
if (i == count)
count++;
}
}
internal string GetColumnError(DataColumn column) {
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
return errorList[i].error;
}
}
return String.Empty;
}
internal void Clear(DataColumn column) {
if (count == 0)
return;
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
System.Array.Copy(errorList, i+1, errorList, i, count-i-1);
count--;
column.errors--;
Debug.Assert(column.errors >= 0, "missing error counts");
}
}
}
internal void Clear() {
for (int i = 0; i < count; i++) {
errorList[i].column.errors--;
Debug.Assert(errorList[i].column.errors >= 0, "missing error counts");
}
count = 0;
rowError = String.Empty;
}
internal DataColumn[] GetColumnsInError() {
DataColumn[] cols = new DataColumn[count];
for (int i = 0; i < count; i++) {
cols[i] = errorList[i].column;
}
return cols;
}
///
/// Sets the error message for the .
///
private void SetText(string errorText) {
if (null == errorText) {
errorText = String.Empty;
}
rowError = errorText;
}
internal int IndexOf (DataColumn column) {
// try to find the column
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
return i;
}
}
if (count >= errorList.Length) {
int newCapacity = Math.Min(count*2, column.Table.Columns.Count);
ColumnError[] biggerList = new ColumnError[newCapacity];
System.Array.Copy(errorList, 0, biggerList, 0, count);
errorList = biggerList;
}
return count;
}
internal struct ColumnError {
internal DataColumn column;
internal string error;
};
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data {
using System;
using System.Diagnostics;
///
/// Represents an custom error that can be associated with a .
///
internal sealed class DataError {
private string rowError = String.Empty;
// column-level errors
private int count;
private ColumnError[] errorList;
internal const int initialCapacity = 1;
internal DataError() {
}
internal DataError(string rowError) {
SetText(rowError);
}
internal string Text {
get {
return rowError;
}
set {
SetText(value);
}
}
internal bool HasErrors {
get {
return(rowError.Length != 0 || count != 0);
}
}
//
// this method resets the error to the new value.
//
internal void SetColumnError(DataColumn column, string error) {
Debug.Assert(column != null, "Invalid (null) argument");
Debug.Assert(column.Table != null, "Invalid (loose) column");
if (error == null || error.Length == 0) {
// remove error from the collection
Clear(column);
}
else {
if (errorList == null) {
errorList = new ColumnError[initialCapacity];
}
int i = IndexOf(column);
errorList[i].column = column;
errorList[i].error = error;
column.errors++;
if (i == count)
count++;
}
}
internal string GetColumnError(DataColumn column) {
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
return errorList[i].error;
}
}
return String.Empty;
}
internal void Clear(DataColumn column) {
if (count == 0)
return;
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
System.Array.Copy(errorList, i+1, errorList, i, count-i-1);
count--;
column.errors--;
Debug.Assert(column.errors >= 0, "missing error counts");
}
}
}
internal void Clear() {
for (int i = 0; i < count; i++) {
errorList[i].column.errors--;
Debug.Assert(errorList[i].column.errors >= 0, "missing error counts");
}
count = 0;
rowError = String.Empty;
}
internal DataColumn[] GetColumnsInError() {
DataColumn[] cols = new DataColumn[count];
for (int i = 0; i < count; i++) {
cols[i] = errorList[i].column;
}
return cols;
}
///
/// Sets the error message for the .
///
private void SetText(string errorText) {
if (null == errorText) {
errorText = String.Empty;
}
rowError = errorText;
}
internal int IndexOf (DataColumn column) {
// try to find the column
for (int i = 0; i < count; i++) {
if (errorList[i].column == column) {
return i;
}
}
if (count >= errorList.Length) {
int newCapacity = Math.Min(count*2, column.Table.Columns.Count);
ColumnError[] biggerList = new ColumnError[newCapacity];
System.Array.Copy(errorList, 0, biggerList, 0, count);
errorList = biggerList;
}
return count;
}
internal struct ColumnError {
internal DataColumn column;
internal string error;
};
}
}
// 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
- MSAAEventDispatcher.cs
- Input.cs
- HttpRequest.cs
- ButtonAutomationPeer.cs
- PageParser.cs
- RoleServiceManager.cs
- JsonDeserializer.cs
- SqlClientWrapperSmiStream.cs
- ComplusEndpointConfigContainer.cs
- NullableLongMinMaxAggregationOperator.cs
- NetSectionGroup.cs
- DataReaderContainer.cs
- AssemblyBuilder.cs
- SafeMILHandle.cs
- CustomCategoryAttribute.cs
- GridViewRow.cs
- SafePointer.cs
- CompiledIdentityConstraint.cs
- ExtensibleClassFactory.cs
- Point3DCollectionValueSerializer.cs
- CustomAttribute.cs
- EntitySetBaseCollection.cs
- ProtectedConfiguration.cs
- PropertyFilterAttribute.cs
- XmlSerializationWriter.cs
- RedirectionProxy.cs
- MenuRendererClassic.cs
- PointHitTestParameters.cs
- PropertyChangedEventManager.cs
- Ref.cs
- Brush.cs
- CodeFieldReferenceExpression.cs
- CustomErrorCollection.cs
- Catch.cs
- SchemaSetCompiler.cs
- ControlTemplate.cs
- FileLevelControlBuilderAttribute.cs
- Wildcard.cs
- AuthenticationService.cs
- NativeMethodsCLR.cs
- XmlUtf8RawTextWriter.cs
- IndexedEnumerable.cs
- CancelEventArgs.cs
- ListItem.cs
- WinFormsSpinner.cs
- TypeElementCollection.cs
- HttpGetProtocolImporter.cs
- HttpResponseInternalWrapper.cs
- RIPEMD160.cs
- ConstraintCollection.cs
- _UncName.cs
- FileRecordSequence.cs
- ChangeBlockUndoRecord.cs
- HostDesigntimeLicenseContext.cs
- ProtectedConfiguration.cs
- DbCommandTree.cs
- ConvertTextFrag.cs
- EditCommandColumn.cs
- UnknownBitmapDecoder.cs
- NameObjectCollectionBase.cs
- SubtreeProcessor.cs
- HtmlGenericControl.cs
- FilterableAttribute.cs
- OleCmdHelper.cs
- NotificationContext.cs
- Scene3D.cs
- SchemaNamespaceManager.cs
- ComponentCollection.cs
- DatatypeImplementation.cs
- _NtlmClient.cs
- ManagementScope.cs
- SamlSerializer.cs
- UdpSocket.cs
- CryptoProvider.cs
- IsolatedStorageFile.cs
- ParseNumbers.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- StructuredTypeEmitter.cs
- OracleRowUpdatedEventArgs.cs
- FontCollection.cs
- DateTimeSerializationSection.cs
- MediaEntryAttribute.cs
- EdmComplexTypeAttribute.cs
- DynamicExpression.cs
- ControlBindingsCollection.cs
- PointCollectionConverter.cs
- ListSortDescription.cs
- XPathNavigatorReader.cs
- ListSortDescription.cs
- Registry.cs
- dataobject.cs
- ElementUtil.cs
- HttpResponse.cs
- ToolZone.cs
- SerializationInfoEnumerator.cs
- cache.cs
- TextEditorSpelling.cs
- WebPartDescriptionCollection.cs
- WebBaseEventKeyComparer.cs
- VisualBrush.cs