Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / DataError.cs / 1305376 / 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
- CodeTypeMember.cs
- ComponentDispatcher.cs
- ScriptRegistrationManager.cs
- InkCanvasInnerCanvas.cs
- SelectionWordBreaker.cs
- WebBrowserNavigatedEventHandler.cs
- UpnEndpointIdentityExtension.cs
- RtfToXamlLexer.cs
- RelationshipEnd.cs
- SymbolTable.cs
- compensatingcollection.cs
- _IPv6Address.cs
- RegexGroupCollection.cs
- ContainerParaClient.cs
- SiteIdentityPermission.cs
- CqlIdentifiers.cs
- FormatSettings.cs
- EventWaitHandle.cs
- MainMenu.cs
- RadioButtonList.cs
- SelectionEditingBehavior.cs
- MediaContext.cs
- DifferencingCollection.cs
- nulltextnavigator.cs
- ClockController.cs
- HttpFileCollectionWrapper.cs
- Listbox.cs
- NativeObjectSecurity.cs
- OracleTimeSpan.cs
- HttpStaticObjectsCollectionBase.cs
- Matrix.cs
- DateTimeOffsetConverter.cs
- DiscreteKeyFrames.cs
- ControlBuilderAttribute.cs
- NumericUpDown.cs
- SearchForVirtualItemEventArgs.cs
- KeyInterop.cs
- SqlDataSourceRefreshSchemaForm.cs
- rsa.cs
- WinFormsSecurity.cs
- XDRSchema.cs
- ToolBarButton.cs
- OneOfTypeConst.cs
- ViewLoader.cs
- FunctionImportMapping.cs
- MobileTextWriter.cs
- HierarchicalDataBoundControl.cs
- WindowsContainer.cs
- EventDrivenDesigner.cs
- DynamicResourceExtension.cs
- SplitterPanel.cs
- AssemblyInfo.cs
- XPathAncestorIterator.cs
- ParseElementCollection.cs
- CryptoConfig.cs
- TextServicesDisplayAttribute.cs
- SecurityKeyIdentifierClause.cs
- MemoryRecordBuffer.cs
- ServiceHttpHandlerFactory.cs
- StylusPointProperty.cs
- OrderByQueryOptionExpression.cs
- ControlCachePolicy.cs
- SmtpClient.cs
- MeshGeometry3D.cs
- WebMessageEncodingElement.cs
- wgx_commands.cs
- ExternalException.cs
- Camera.cs
- PreviewControlDesigner.cs
- InvalidCastException.cs
- TextOutput.cs
- SequentialWorkflowRootDesigner.cs
- MemberMaps.cs
- DataGridTable.cs
- WebEventCodes.cs
- OdbcError.cs
- DirectoryInfo.cs
- MissingMethodException.cs
- WebPartDescription.cs
- BamlResourceSerializer.cs
- PasswordBox.cs
- DataStorage.cs
- RequestReplyCorrelator.cs
- DelegateBodyWriter.cs
- TransportChannelListener.cs
- PageFunction.cs
- _TLSstream.cs
- NavigationWindow.cs
- BitArray.cs
- WebHttpBindingElement.cs
- SqlMetaData.cs
- ColumnClickEvent.cs
- SQLBinaryStorage.cs
- PenLineCapValidation.cs
- StreamHelper.cs
- FieldAccessException.cs
- ExpressionWriter.cs
- MethodExpr.cs
- ScriptModule.cs
- ISFTagAndGuidCache.cs