Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ObjectDisposedException.Throw for object instance and type #58684

Merged
merged 21 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override int Read(byte[] buffer, int offset, int count)
{
if (_remaining < 0)
{
throw new ObjectDisposedException(typeof(PositionValueStream).Name);
ObjectDisposedException.Throw(typeof(PositionValueStream));
jeffhandley marked this conversation as resolved.
Show resolved Hide resolved
}

if (_remaining == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void ThrowIfDisposed()
ThrowObjectDisposedException();
}

void ThrowObjectDisposedException() => throw new ObjectDisposedException(GetType().FullName);
void ThrowObjectDisposedException() => ObjectDisposedException.Throw(this);
jeffhandley marked this conversation as resolved.
Show resolved Hide resolved
}

private static IOException WrapException(string resourceFormatString, Exception innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private void CheckDisposed()
Throw();
}

static void Throw() => throw new ObjectDisposedException(typeof(MemoryCache).FullName);
static void Throw() => ObjectDisposedException.Throw(typeof(MemoryCache));
}

private static void ValidateCacheKey(object key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void FailObjectDisposed<TDisposed>(TDisposed disposed)
{
// separating out this throwing helps with inlining of the caller, especially
// due to the retrieval of the type's name
throw new ObjectDisposedException(disposed!.GetType().FullName);
ObjectDisposedException.Throw(disposed!);
jeffhandley marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private void ThrowIfDisposed()
{
if (_isDisposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,13 @@ public int Value
get
{
if (this.IsDisposed)
throw new ObjectDisposedException(this.GetType().Name);
ObjectDisposedException.Throw(this);
return this._value;
}
set
{
if (this.IsDisposed)
throw new ObjectDisposedException(this.GetType().Name);
ObjectDisposedException.Throw(this);
this._value = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public bool Enabled
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

int i = (int)Math.Ceiling(_interval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void Dispose()
// Stacks should never be popped out of order.
// We want to trap this condition in production.
Debug.Fail("Scope was popped out of order.");
throw new ObjectDisposedException(GetType().FullName);
ObjectDisposedException.Throw(this);
}

m_deserializationToken.Dispose(); // it's a readonly struct, but Dispose still works properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private CNativeBuffer Buffer
if (null == value)
{
Debug.Fail("object is disposed");
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.OleDb/src/OleDbDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private UnsafeNativeMethods.IRowset IRowset()
if (null == irowset)
{
Debug.Assert(false, "object is disposed");
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}
return irowset;
}
Expand All @@ -248,7 +248,7 @@ private UnsafeNativeMethods.IRow IRow()
if (null == irow)
{
Debug.Assert(false, "object is disposed");
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}
return irow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ public void ModifyOverflowPolicy(OverflowAction action, int retentionDays)
private void OpenForRead(string currentMachineName)
{
if (this.boolFlags[Flag_disposed])
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);

string logname = GetLogName(currentMachineName);

Expand Down Expand Up @@ -1083,7 +1083,7 @@ private void OpenForWrite(string currentMachineName)
{
//Cannot allocate the writeHandle if the object has been disposed, since finalization has been suppressed.
if (this.boolFlags[Flag_disposed])
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);

if (sourceName == null || sourceName.Length == 0)
throw new ArgumentException(SR.NeedSourceToOpen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ private void CheckDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public DirectoryResponse SendRequest(DirectoryRequest request, TimeSpan requestT
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (request == null)
Expand Down Expand Up @@ -293,7 +293,7 @@ public IAsyncResult BeginSendRequest(DirectoryRequest request, TimeSpan requestT
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (request == null)
Expand Down Expand Up @@ -413,7 +413,7 @@ public void Abort(IAsyncResult asyncResult)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (asyncResult == null)
Expand Down Expand Up @@ -461,7 +461,7 @@ public PartialResultsCollection GetPartialResults(IAsyncResult asyncResult)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (asyncResult == null)
Expand All @@ -486,7 +486,7 @@ public DirectoryResponse EndSendRequest(IAsyncResult asyncResult)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (asyncResult == null)
Expand Down Expand Up @@ -1030,7 +1030,7 @@ private void BindHelper(NetworkCredential newCredential, bool needSetCredential)
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

// Throw if user wants to do anonymous bind but specifies credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public bool SecureSocketLayer
{
get
{
if (_connection._disposed) throw new ObjectDisposedException(GetType().Name);
if (_connection._disposed) ObjectDisposedException.Throw(this);
return _secureSocketLayer;
}
set
{
if (_connection._disposed) throw new ObjectDisposedException(GetType().Name);
if (_connection._disposed) ObjectDisposedException.Throw(this);
_secureSocketLayer = value;
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ private bool GetBoolValueHelper(LdapOption option)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

bool outValue = false;
Expand All @@ -70,7 +70,7 @@ private void SetBoolValueHelper(LdapOption option, bool value)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

int error = LdapPal.SetBoolOption(_connection._ldapHandle, option, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public SecurityPackageContextConnectionInformation SslInformation
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

var secInfo = new SecurityPackageContextConnectionInformation();
Expand All @@ -293,7 +293,7 @@ public object SecurityContext
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

SecurityHandle tempHandle = default;
Expand Down Expand Up @@ -398,7 +398,7 @@ public ReferralCallback ReferralCallback
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

return _callbackRoutine;
Expand All @@ -407,7 +407,7 @@ public ReferralCallback ReferralCallback
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

var tempCallback = new ReferralCallback();
Expand Down Expand Up @@ -436,7 +436,7 @@ public QueryClientCertificateCallback QueryClientCertificate
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

return _clientCertificateDelegate;
Expand All @@ -445,7 +445,7 @@ public QueryClientCertificateCallback QueryClientCertificate
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (value != null)
Expand Down Expand Up @@ -478,7 +478,7 @@ public VerifyServerCertificateCallback VerifyServerCertificate
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

return _serverCertificateDelegate;
Expand All @@ -487,7 +487,7 @@ public VerifyServerCertificateCallback VerifyServerCertificate
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

if (value != null)
Expand Down Expand Up @@ -518,7 +518,7 @@ public void FastConcurrentBind()
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}


Expand All @@ -545,7 +545,7 @@ public unsafe void StartTransportLayerSecurity(DirectoryControlCollection contro

if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

try
Expand Down Expand Up @@ -726,7 +726,7 @@ public void StopTransportLayerSecurity()
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

byte result = LdapPal.StopTls(_connection._ldapHandle);
Expand All @@ -740,7 +740,7 @@ private int GetIntValueHelper(LdapOption option)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

int outValue = 0;
Expand All @@ -754,7 +754,7 @@ private void SetIntValueHelper(LdapOption option, int value)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

int temp = value;
Expand All @@ -767,7 +767,7 @@ private IntPtr GetPtrValueHelper(LdapOption option)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

IntPtr outValue = new IntPtr(0);
Expand All @@ -781,7 +781,7 @@ private void SetPtrValueHelper(LdapOption option, IntPtr value)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

IntPtr temp = value;
Expand All @@ -794,7 +794,7 @@ private string GetStringValueHelper(LdapOption option, bool releasePtr)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

IntPtr outValue = new IntPtr(0);
Expand All @@ -819,7 +819,7 @@ private void SetStringValueHelper(LdapOption option, string value)
{
if (_connection._disposed)
{
throw new ObjectDisposedException(GetType().Name);
ObjectDisposedException.Throw(this);
}

IntPtr inValue = IntPtr.Zero;
Expand Down
Loading