Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataSet / System / Data / DataSetUtil.cs / 1 / DataSetUtil.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.DataSetExtensions;
using System.Diagnostics;
internal static class DataSetUtil
{
#region CheckArgument
internal static void CheckArgumentNull(T argumentValue, string argumentName) where T : class
{
if (null == argumentValue)
{
throw ArgumentNull(argumentName);
}
}
#endregion
#region Trace
private static T TraceException(string trace, T e)
{
Debug.Assert(null != e, "TraceException: null Exception");
if (null != e)
{
//Bid.Trace(trace, e.ToString()); // will include callstack if permission is available
}
return e;
}
private static T TraceExceptionAsReturnValue(T e)
{
return TraceException(" '%ls'\n", e);
}
#endregion
#region new Exception
internal static ArgumentException Argument(string message)
{
return TraceExceptionAsReturnValue(new ArgumentException(message));
}
internal static ArgumentNullException ArgumentNull(string message)
{
return TraceExceptionAsReturnValue(new ArgumentNullException(message));
}
internal static ArgumentOutOfRangeException ArgumentOutOfRange(string message, string parameterName)
{
return TraceExceptionAsReturnValue(new ArgumentOutOfRangeException(parameterName, message));
}
internal static InvalidCastException InvalidCast(string message)
{
return TraceExceptionAsReturnValue(new InvalidCastException(message));
}
internal static InvalidOperationException InvalidOperation(string message)
{
return TraceExceptionAsReturnValue(new InvalidOperationException(message));
}
internal static NotSupportedException NotSupported(string message)
{
return TraceExceptionAsReturnValue(new NotSupportedException(message));
}
#endregion
#region new EnumerationValueNotValid
static internal ArgumentOutOfRangeException InvalidEnumerationValue(Type type, int value)
{
return ArgumentOutOfRange(Strings.DataSetLinq_InvalidEnumerationValue(type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name);
}
static internal ArgumentOutOfRangeException InvalidDataRowState(DataRowState value)
{
#if DEBUG
switch (value)
{
case DataRowState.Detached:
case DataRowState.Unchanged:
case DataRowState.Added:
case DataRowState.Deleted:
case DataRowState.Modified:
Debug.Assert(false, "valid DataRowState " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(DataRowState), (int)value);
}
static internal ArgumentOutOfRangeException InvalidLoadOption(LoadOption value)
{
#if DEBUG
switch (value)
{
case LoadOption.OverwriteChanges:
case LoadOption.PreserveChanges:
case LoadOption.Upsert:
Debug.Assert(false, "valid LoadOption " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(LoadOption), (int)value);
}
#endregion
// only StackOverflowException & ThreadAbortException are sealed classes
static private readonly Type StackOverflowType = typeof(System.StackOverflowException);
static private readonly Type OutOfMemoryType = typeof(System.OutOfMemoryException);
static private readonly Type ThreadAbortType = typeof(System.Threading.ThreadAbortException);
static private readonly Type NullReferenceType = typeof(System.NullReferenceException);
static private readonly Type AccessViolationType = typeof(System.AccessViolationException);
static private readonly Type SecurityType = typeof(System.Security.SecurityException);
static internal bool IsCatchableExceptionType(Exception e)
{
// a 'catchable' exception is defined by what it is not.
Type type = e.GetType();
return ((type != StackOverflowType) &&
(type != OutOfMemoryType) &&
(type != ThreadAbortType) &&
(type != NullReferenceType) &&
(type != AccessViolationType) &&
!SecurityType.IsAssignableFrom(type));
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.DataSetExtensions;
using System.Diagnostics;
internal static class DataSetUtil
{
#region CheckArgument
internal static void CheckArgumentNull(T argumentValue, string argumentName) where T : class
{
if (null == argumentValue)
{
throw ArgumentNull(argumentName);
}
}
#endregion
#region Trace
private static T TraceException(string trace, T e)
{
Debug.Assert(null != e, "TraceException: null Exception");
if (null != e)
{
//Bid.Trace(trace, e.ToString()); // will include callstack if permission is available
}
return e;
}
private static T TraceExceptionAsReturnValue(T e)
{
return TraceException(" '%ls'\n", e);
}
#endregion
#region new Exception
internal static ArgumentException Argument(string message)
{
return TraceExceptionAsReturnValue(new ArgumentException(message));
}
internal static ArgumentNullException ArgumentNull(string message)
{
return TraceExceptionAsReturnValue(new ArgumentNullException(message));
}
internal static ArgumentOutOfRangeException ArgumentOutOfRange(string message, string parameterName)
{
return TraceExceptionAsReturnValue(new ArgumentOutOfRangeException(parameterName, message));
}
internal static InvalidCastException InvalidCast(string message)
{
return TraceExceptionAsReturnValue(new InvalidCastException(message));
}
internal static InvalidOperationException InvalidOperation(string message)
{
return TraceExceptionAsReturnValue(new InvalidOperationException(message));
}
internal static NotSupportedException NotSupported(string message)
{
return TraceExceptionAsReturnValue(new NotSupportedException(message));
}
#endregion
#region new EnumerationValueNotValid
static internal ArgumentOutOfRangeException InvalidEnumerationValue(Type type, int value)
{
return ArgumentOutOfRange(Strings.DataSetLinq_InvalidEnumerationValue(type.Name, value.ToString(System.Globalization.CultureInfo.InvariantCulture)), type.Name);
}
static internal ArgumentOutOfRangeException InvalidDataRowState(DataRowState value)
{
#if DEBUG
switch (value)
{
case DataRowState.Detached:
case DataRowState.Unchanged:
case DataRowState.Added:
case DataRowState.Deleted:
case DataRowState.Modified:
Debug.Assert(false, "valid DataRowState " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(DataRowState), (int)value);
}
static internal ArgumentOutOfRangeException InvalidLoadOption(LoadOption value)
{
#if DEBUG
switch (value)
{
case LoadOption.OverwriteChanges:
case LoadOption.PreserveChanges:
case LoadOption.Upsert:
Debug.Assert(false, "valid LoadOption " + value.ToString());
break;
}
#endif
return InvalidEnumerationValue(typeof(LoadOption), (int)value);
}
#endregion
// only StackOverflowException & ThreadAbortException are sealed classes
static private readonly Type StackOverflowType = typeof(System.StackOverflowException);
static private readonly Type OutOfMemoryType = typeof(System.OutOfMemoryException);
static private readonly Type ThreadAbortType = typeof(System.Threading.ThreadAbortException);
static private readonly Type NullReferenceType = typeof(System.NullReferenceException);
static private readonly Type AccessViolationType = typeof(System.AccessViolationException);
static private readonly Type SecurityType = typeof(System.Security.SecurityException);
static internal bool IsCatchableExceptionType(Exception e)
{
// a 'catchable' exception is defined by what it is not.
Type type = e.GetType();
return ((type != StackOverflowType) &&
(type != OutOfMemoryType) &&
(type != ThreadAbortType) &&
(type != NullReferenceType) &&
(type != AccessViolationType) &&
!SecurityType.IsAssignableFrom(type));
}
}
// 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
- SmiRequestExecutor.cs
- EventPrivateKey.cs
- XmlHierarchyData.cs
- CancellationScope.cs
- Processor.cs
- FontUnitConverter.cs
- Pair.cs
- TraceFilter.cs
- StyleHelper.cs
- DataGridViewLinkCell.cs
- PropertyTab.cs
- TextEndOfSegment.cs
- SmtpMail.cs
- SeparatorAutomationPeer.cs
- DataGridView.cs
- CloudCollection.cs
- SqlDataSourceView.cs
- URLMembershipCondition.cs
- QilReplaceVisitor.cs
- CryptoConfig.cs
- KnownBoxes.cs
- JournalEntryListConverter.cs
- DetectEofStream.cs
- InheritanceContextChangedEventManager.cs
- AccessibleObject.cs
- SafeRsaProviderHandle.cs
- AmbientLight.cs
- ISSmlParser.cs
- AttributeSetAction.cs
- FixedStringLookup.cs
- InternalDispatchObject.cs
- InvalidAsynchronousStateException.cs
- _IPv4Address.cs
- XPathPatternBuilder.cs
- WeakEventManager.cs
- DataGridAutoGeneratingColumnEventArgs.cs
- StreamWriter.cs
- OleDragDropHandler.cs
- LinqToSqlWrapper.cs
- Size3DConverter.cs
- adornercollection.cs
- ResourceAssociationSet.cs
- OdbcUtils.cs
- ManualWorkflowSchedulerService.cs
- WebPartChrome.cs
- _TransmitFileOverlappedAsyncResult.cs
- GlyphCollection.cs
- DeploymentSection.cs
- SecureUICommand.cs
- DesigntimeLicenseContextSerializer.cs
- Itemizer.cs
- ConfigXmlDocument.cs
- QueryAsyncResult.cs
- MergeFailedEvent.cs
- CalendarDataBindingHandler.cs
- TextTrailingWordEllipsis.cs
- HyperLink.cs
- _ConnectOverlappedAsyncResult.cs
- SimpleType.cs
- diagnosticsswitches.cs
- GACIdentityPermission.cs
- ControlBindingsCollection.cs
- DynamicArgumentDesigner.xaml.cs
- ColorBlend.cs
- EventBuilder.cs
- SspiNegotiationTokenProviderState.cs
- ToolboxBitmapAttribute.cs
- ProfileService.cs
- DataContractSerializerFaultFormatter.cs
- InvalidCastException.cs
- OrthographicCamera.cs
- TheQuery.cs
- WebBrowsableAttribute.cs
- AttributeAction.cs
- DrawingCollection.cs
- ElapsedEventArgs.cs
- DataGridViewDataErrorEventArgs.cs
- OracleTransaction.cs
- UriTemplateVariablePathSegment.cs
- WebColorConverter.cs
- GlobalProxySelection.cs
- XmlMembersMapping.cs
- SqlFacetAttribute.cs
- IconHelper.cs
- IODescriptionAttribute.cs
- IUnknownConstantAttribute.cs
- ScriptManagerProxy.cs
- SimpleFileLog.cs
- util.cs
- ValidatorCollection.cs
- ServiceHandle.cs
- EdmItemCollection.OcAssemblyCache.cs
- IDReferencePropertyAttribute.cs
- DataMemberConverter.cs
- COAUTHINFO.cs
- AmbientLight.cs
- Resources.Designer.cs
- DBParameter.cs
- NetWebProxyFinder.cs
- XPathNode.cs