Closed
Description
Background and Motivation
There is a very common pattern used to handle disposed object state and it involves throwing ObjectDisposedException
. It requires extra conversion before constructing the exception. There are about 400 cases of this pattern in runtime which could be unified and simplified and more in .NET libraries.
throw new ObjectDisposedException(GetType().FullName);
// or
throw new ObjectDisposedException(GetType().Name);
// or
throw new ObjectDisposedException(GetType().ToString());
// or
throw new ObjectDisposedException(nameof(NameOfThisType));
Proposed API
namespace System
{
public class ObjectDisposedException {
+ public ObjectDisposedException(object instance);
}
Usage Examples
All the examples from above could be replaced with simple construction which would extract the name from the instance.
throw new ObjectDisposedException(this);