Skip to content

Commit

Permalink
Seal internal types in libraries (dotnet#50225)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Mar 26, 2021
1 parent 9e58052 commit 0817e74
Show file tree
Hide file tree
Showing 969 changed files with 1,569 additions and 1,564 deletions.
3 changes: 2 additions & 1 deletion docs/coding-guidelines/coding-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The general rule we follow is "use Visual Studio defaults".
Consider enabling "View White Space (Ctrl+R, Ctrl+W)" or "Edit -> Advanced -> View White Space" if using Visual Studio to aid detection.
9. If a file happens to differ in style from these guidelines (e.g. private members are named `m_member`
rather than `_member`), the existing style in that file takes precedence.
10. We only use `var` when it's obvious what the variable type is (e.g. `var stream = new FileStream(...)` not `var stream = OpenStandardInput()`).
10. We only use `var` when the type is explicitly named on the right-hand side, typically due to either `new` or an explicit cast, e.g. `var stream = new FileStream(...)` not `var stream = OpenStandardInput()`.
11. We use language keywords instead of BCL types (e.g. `int, string, float` instead of `Int32, String, Single`, etc) for both type references as well as method calls (e.g. `int.Parse` instead of `Int32.Parse`). See issue [#13976](https://github.com/dotnet/runtime/issues/13976) for examples.
12. We use PascalCasing to name all our constant local variables and fields. The only exception is for interop code where the constant value should exactly match the name and value of the code you are calling via interop.
13. We use PascalCasing for all method names, including local functions.
Expand All @@ -35,6 +35,7 @@ The general rule we follow is "use Visual Studio defaults".
- Never use single-line form (for example: `if (source == null) throw new ArgumentNullException("source");`)
- Using braces is always accepted, and required if any block of an `if`/`else if`/.../`else` compound statement uses braces or if a single statement body spans multiple lines.
- Braces may be omitted only if the body of *every* block associated with an `if`/`else if`/.../`else` compound statement is placed on a single line.
19. Make all internal and private types static or sealed unless derivation from them is required. As with any implementation detail, they can be changed if/when derivation is required in the future.

An [EditorConfig](https://editorconfig.org "EditorConfig homepage") file (`.editorconfig`) has been provided at the root of the runtime repository, enabling C# auto-formatting conforming to the above guidelines.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal interface IArraySortHelper<TKey>
}

[TypeDependency("System.Collections.Generic.GenericArraySortHelper`1")]
internal partial class ArraySortHelper<T>
internal sealed partial class ArraySortHelper<T>
: IArraySortHelper<T>
{
private static readonly IArraySortHelper<T> s_defaultArraySortHelper = CreateArraySortHelper();
Expand All @@ -37,7 +37,7 @@ private static IArraySortHelper<T> CreateArraySortHelper()
}
}

internal partial class GenericArraySortHelper<T>
internal sealed partial class GenericArraySortHelper<T>
: IArraySortHelper<T>
{
}
Expand All @@ -48,7 +48,7 @@ internal interface IArraySortHelper<TKey, TValue>
}

[TypeDependency("System.Collections.Generic.GenericArraySortHelper`2")]
internal partial class ArraySortHelper<TKey, TValue>
internal sealed partial class ArraySortHelper<TKey, TValue>
: IArraySortHelper<TKey, TValue>
{
private static readonly IArraySortHelper<TKey, TValue> s_defaultArraySortHelper = CreateArraySortHelper();
Expand All @@ -72,7 +72,7 @@ private static IArraySortHelper<TKey, TValue> CreateArraySortHelper()
}
}

internal partial class GenericArraySortHelper<TKey, TValue>
internal sealed partial class GenericArraySortHelper<TKey, TValue>
: IArraySortHelper<TKey, TValue>
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace System.Resources
{
internal partial class ManifestBasedResourceGroveler
internal sealed partial class ManifestBasedResourceGroveler
{
// Internal version of GetSatelliteAssembly that avoids throwing FileNotFoundException
private static Assembly? InternalGetSatelliteAssembly(Assembly mainAssembly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace System.Threading
{
internal partial class TimerQueue
internal sealed partial class TimerQueue
{
#region interface to native per-AppDomain timer

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/Extensions/EmptyDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.Extensions.FileProviders
{
internal class EmptyDisposable : IDisposable
internal sealed class EmptyDisposable : IDisposable
{
public static EmptyDisposable Instance { get; } = new EmptyDisposable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Logging
/// <summary>
/// Scope provider that does nothing.
/// </summary>
internal class NullExternalScopeProvider : IExternalScopeProvider
internal sealed class NullExternalScopeProvider : IExternalScopeProvider
{
private NullExternalScopeProvider()
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/Extensions/Logging/NullScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.Extensions.Logging
/// <summary>
/// An empty scope without any logic
/// </summary>
internal class NullScope : IDisposable
internal sealed class NullScope : IDisposable
{
public static NullScope Instance { get; } = new NullScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static partial class AndroidCrypto
[DllImport(Interop.Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRelease")]
internal static extern void SSLStreamRelease(IntPtr ptr);

internal class SslException : Exception
internal sealed class SslException : Exception
{
internal SslException()
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/Interop/Interop.Ldap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static partial class Interop
namespace System.DirectoryServices.Protocols
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal class Luid
internal sealed class Luid
{
private readonly int _lowPart;
private readonly int _highPart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal struct SaslDefaultCredentials
/// where we will have to resolve the result.
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal class SaslInteractiveChallenge
internal sealed class SaslInteractiveChallenge
{
public ulong saslChallengeType;
public string challenge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal struct CFStreamClientContext
public IntPtr CopyDescription;
}

internal class CFProxy
internal sealed class CFProxy
{
private SafeCFDictionaryHandle _dictionary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
{
internal static partial class AppleCrypto
{
internal class SslException : Exception
internal sealed class SslException : Exception
{
internal SslException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
internal static partial class Advapi32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal class ENUM_SERVICE_STATUS
internal sealed class ENUM_SERVICE_STATUS
{
internal string? serviceName;
internal string? displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
internal static partial class Advapi32
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal class ENUM_SERVICE_STATUS_PROCESS
internal sealed class ENUM_SERVICE_STATUS_PROCESS
{
internal string? serviceName;
internal string? displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Interop
internal static partial class CryptUI
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal class CRYPTUI_VIEWCERTIFICATE_STRUCTW
internal sealed class CRYPTUI_VIEWCERTIFICATE_STRUCTW
{
internal uint dwSize;
internal IntPtr hwndParent;
Expand All @@ -33,7 +33,7 @@ internal class CRYPTUI_VIEWCERTIFICATE_STRUCTW
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal class CRYPTUI_SELECTCERTIFICATE_STRUCTW
internal sealed class CRYPTUI_SELECTCERTIFICATE_STRUCTW
{
internal uint dwSize;
internal IntPtr hwndParent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace System.Net
{
// _SecPkgInfoW in sspi.h.
internal class SecurityPackageInfoClass
internal sealed class SecurityPackageInfoClass
{
internal int Capabilities;
internal short Version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
internal static partial class WinMM
{
[StructLayout(LayoutKind.Sequential)]
internal class MMCKINFO
internal sealed class MMCKINFO
{
internal int ckID;
internal int cksize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static partial class Interop
internal static partial class WinMM
{
[StructLayout(LayoutKind.Sequential)]
internal class WAVEFORMATEX
internal sealed class WAVEFORMATEX
{
internal short wFormatTag;
internal short nChannels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal enum CodeTypeReferenceOptions
#if !FEATURE_SERIALIZATION
public class CodeTypeReference : CodeObject
#else
internal class CodeTypeReference : CodeObject
internal sealed class CodeTypeReference : CodeObject
#endif
{
private string? _baseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace System.Runtime.Serialization
#if !FEATURE_SERIALIZATION
public class CodeTypeReferenceCollection : CollectionBase
#else
internal class CodeTypeReferenceCollection : CollectionBase
internal sealed class CodeTypeReferenceCollection : CollectionBase
#endif
{
public CodeTypeReferenceCollection() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace System.Data.Common
{
// DbConnectionPoolKey: Base class implementation of a key to connection pool groups
// Only connection string is used as a key
internal class DbConnectionPoolKey : ICloneable
internal sealed class DbConnectionPoolKey : ICloneable
{
private string? _connectionString;

Expand All @@ -14,17 +14,17 @@ internal DbConnectionPoolKey(string? connectionString)
_connectionString = connectionString;
}

protected DbConnectionPoolKey(DbConnectionPoolKey key)
private DbConnectionPoolKey(DbConnectionPoolKey key)
{
_connectionString = key.ConnectionString;
}

public virtual object Clone()
public object Clone()
{
return new DbConnectionPoolKey(this);
}

internal virtual string? ConnectionString
internal string? ConnectionString
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.Data.ProviderBase
// Get remaining time in appropriate format to pass to subsystem timeouts
// Check for timeout via IsExpired for checks in managed code.
// Simply abandon to GC when done.
internal class TimeoutTimer
internal sealed class TimeoutTimer
{
//-------------------
// Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Net
{
internal class CaseInsensitiveAscii : IEqualityComparer, IComparer
internal sealed class CaseInsensitiveAscii : IEqualityComparer, IComparer
{
// ASCII char ToLower table
internal static readonly CaseInsensitiveAscii StaticInstance = new CaseInsensitiveAscii();
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Net/ContextAwareResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace System.Net
//
// For now the state is not included as part of the closure. It is too common a pattern (for example with socket receive)
// to have several pending IOs differentiated by their state object. We don't want that pattern to break the cache.
internal class CallbackClosure
internal sealed class CallbackClosure
{
private readonly AsyncCallback? _savedCallback;
private readonly ExecutionContext? _savedContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Net.Http
{
// This class is only used on OS versions where WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY
// is not supported (i.e. before Win8.1/Win2K12R2) in the WinHttpOpen() function.
internal class WinInetProxyHelper
internal sealed class WinInetProxyHelper
{
private const int RecentAutoDetectionInterval = 120_000; // 2 minutes in milliseconds.
private readonly string? _autoConfigUrl, _proxy, _proxyBypass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Net.Http.HPack
{
internal class DynamicTable
internal sealed class DynamicTable
{
private HeaderField[] _buffer;
private int _maxSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace System.Net.Http.HPack
{
internal class HPackDecoder
internal sealed class HPackDecoder
{
private enum State : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Net.Http.HPack
{
// TODO: Should this be public?
[Serializable]
internal class HPackDecodingException : Exception
internal sealed class HPackDecodingException : Exception
{
public HPackDecodingException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.Net.Http.HPack
{
// TODO: Should this be public?
[Serializable]
internal class HuffmanDecodingException : Exception, ISerializable
internal sealed class HuffmanDecodingException : Exception, ISerializable
{
public HuffmanDecodingException()
{
Expand All @@ -18,7 +18,7 @@ public HuffmanDecodingException(string message)
{
}

protected HuffmanDecodingException(SerializationInfo info, StreamingContext context)
private HuffmanDecodingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace System.Net.Http.HPack
{
internal class IntegerDecoder
internal sealed class IntegerDecoder
{
private int _i;
private int _m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace System.Net.Http.QPack
{
internal class QPackDecoder : IDisposable
internal sealed class QPackDecoder : IDisposable
{
private enum State
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace System.Net.Http.QPack
{
internal class QPackEncoder
internal sealed class QPackEncoder
{
private IEnumerator<KeyValuePair<string, string>>? _enumerator;

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Net/Mail/MailAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Net.Mail
{
internal class MailAddress
internal sealed class MailAddress
{
public MailAddress(string address)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace System.Net
{
internal partial class NTAuthentication
internal sealed partial class NTAuthentication
{
private bool _isServer;

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Net/TlsStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace System.Net
{
internal class TlsStream : NetworkStream
internal sealed class TlsStream : NetworkStream
{
private readonly SslStream _sslStream;
private readonly string _host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.Runtime.InteropServices
/// managed delegates to COM's connection point based events.
/// </summary>
[SupportedOSPlatform("windows")]
internal partial class ComEventsSink : IDispatch, ICustomQueryInterface
internal sealed partial class ComEventsSink : IDispatch, ICustomQueryInterface
{
private Guid _iidSourceItf;
private ComTypes.IConnectionPoint? _connectionPoint;
Expand Down
Loading

0 comments on commit 0817e74

Please sign in to comment.