Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0a6a0d1

Browse files
committed
Merge pull request #2662 from James-Ko/patch-1
Remove casts to IDisposable where unneeded
2 parents 9ee87b2 + fa6e6a1 commit 0a6a0d1

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

src/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ bool IDictionary.Contains(object key)
13591359
{
13601360
if (key == null) throw new ArgumentNullException("key");
13611361

1362-
return (key is TKey) && ((ConcurrentDictionary<TKey, TValue>)this).ContainsKey((TKey)key);
1362+
return (key is TKey) && this.ContainsKey((TKey)key);
13631363
}
13641364

13651365
/// <summary>Provides an <see cref="T:System.Collections.Generics.IDictionaryEnumerator"/> for the

src/System.Console/src/System/IO/SyncTextReader.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal sealed class SyncTextReader : TextReader
1616
public static SyncTextReader GetSynchronizedTextReader(TextReader reader)
1717
{
1818
Debug.Assert(reader != null);
19-
return reader as SyncTextReader ??
19+
return reader as SyncTextReader ??
2020
new SyncTextReader(reader);
2121
}
2222

@@ -31,8 +31,7 @@ protected override void Dispose(bool disposing)
3131
{
3232
lock (_methodLock)
3333
{
34-
// Explicitly pick up a potentially methodimpl'ed Dispose
35-
((IDisposable)_in).Dispose();
34+
_in.Dispose();
3635
}
3736
}
3837
}
@@ -87,7 +86,7 @@ public override String ReadToEnd()
8786

8887
//
8988
// On SyncTextReader all APIs should run synchronously, even the async ones.
90-
// No explicit locking is needed, as they all just delegate
89+
// No explicit locking is needed, as they all just delegate
9190
//
9291

9392
public override Task<String> ReadLineAsync()

src/System.Console/src/System/IO/SyncTextWriter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal sealed class SyncTextWriter : TextWriter, IDisposable
1515
internal static SyncTextWriter GetSynchronizedTextWriter(TextWriter writer)
1616
{
1717
Debug.Assert(writer != null);
18-
return writer as SyncTextWriter ??
18+
return writer as SyncTextWriter ??
1919
new SyncTextWriter(writer);
2020
}
2121

@@ -47,8 +47,7 @@ protected override void Dispose(bool disposing)
4747
{
4848
lock (_methodLock)
4949
{
50-
// Explicitly pick up a potentially methodimpl'ed Dispose
51-
((IDisposable)_out).Dispose();
50+
_out.Dispose();
5251
}
5352
}
5453
}

src/System.Linq/src/System/Linq/Enumerable.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,11 @@ public override Iterator<TSource> Clone()
184184

185185
public override void Dispose()
186186
{
187-
if (_enumerator is IDisposable) ((IDisposable)_enumerator).Dispose();
188-
_enumerator = null;
187+
if (_enumerator != null)
188+
{
189+
_enumerator.Dispose();
190+
_enumerator = null;
191+
}
189192
base.Dispose();
190193
}
191194

@@ -347,8 +350,11 @@ public override Iterator<TResult> Clone()
347350

348351
public override void Dispose()
349352
{
350-
if (_enumerator is IDisposable) ((IDisposable)_enumerator).Dispose();
351-
_enumerator = null;
353+
if (_enumerator != null)
354+
{
355+
_enumerator.Dispose();
356+
_enumerator = null;
357+
}
352358
base.Dispose();
353359
}
354360

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlWrappingWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected override void Dispose(bool disposing)
197197
{
198198
if (disposing)
199199
{
200-
((IDisposable)writer).Dispose();
200+
writer.Dispose();
201201
}
202202
}
203203
}

0 commit comments

Comments
 (0)