Skip to content

Commit

Permalink
Seal internal types in runtime libs (#59941)
Browse files Browse the repository at this point in the history
* Fix System.Text.Json

* Fix System.ComponentModel.TypeConverter

* Fix System.Net.Requests

* Fix System.Net.Quic

* Fix System.Linq.Parallel

* Fix Microsoft.CSharp

* Fix System.Private.DataContractSerialization

* Seal types

- System.Security.Cryptography.Algorithms
- System.Diagnostics.Process
- System.Net.HttpListener
- Microsoft.VisualBasic.Core

* Fix System.Diagnostics.DiagnosticSource

* Seal all partials
  • Loading branch information
NewellClark authored Oct 5, 2021
1 parent 9acc383 commit b320541
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Buffers
{
internal unsafe class PointerMemoryManager<T> : MemoryManager<T> where T : struct
internal sealed unsafe class PointerMemoryManager<T> : MemoryManager<T> where T : struct
{
private readonly void* _pointer;
private readonly int _length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace System.Net
{
internal partial class ContextAwareResult
internal sealed partial class ContextAwareResult
{
private void SafeCaptureIdentity()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace System.Net
{
internal partial class ContextAwareResult
internal sealed partial class ContextAwareResult
{
private WindowsIdentity? _windowsIdentity;

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Net/ContextAwareResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal ExecutionContext? Context

// This class will ensure that the correct context is restored on the thread before invoking
// a user callback.
internal partial class ContextAwareResult : LazyAsyncResult
internal sealed partial class ContextAwareResult : LazyAsyncResult
{
[Flags]
private enum StateFlags : byte
Expand Down Expand Up @@ -370,6 +370,6 @@ private void CompleteCallback()
base.Complete(IntPtr.Zero);
}

internal virtual EndPoint? RemoteEndPoint => null;
internal EndPoint? RemoteEndPoint => null;
}
}
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/Net/LazyAsyncResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static ThreadContext CurrentThreadContext
}
}

private class ThreadContext
private sealed class ThreadContext
{
internal int _nestedIOCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class ComEventsMethod
/// handling of this scenario - we are pre-processing delegate's signature by looking for 'ref enums'
/// and cache the types required for such coercion.
/// </summary>
public class DelegateWrapper
public sealed class DelegateWrapper
{
private bool _once;
private int _expectedParamsCount;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/SR.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Imports System.Resources

Namespace System

Friend Class SR
Friend NotInheritable Class SR
' This method is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
' by default it returns false.
' Native code generators can replace the value this returns based on user input at the time of native code generation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics
{
internal sealed partial class CMemberLookupResults
{
public class CMethodIterator
public sealed class CMethodIterator
{
// Inputs.
private readonly AggregateSymbol _context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Imports System.Runtime.InteropServices
Namespace Microsoft.VisualBasic.CompilerServices

' Implements a MRU collection for caching dynamic methods used in IDO late binding.
Friend Class CacheDict(Of TKey, TValue)
Friend NotInheritable Class CacheDict(Of TKey, TValue)
' The Dictionary to quickly access cached data
Private ReadOnly _dict As Dictionary(Of TKey, KeyInfo)
' MRU sorted linked list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Imports System.Diagnostics.CodeAnalysis
Namespace Microsoft.VisualBasic.CompilerServices

' Implements VB conversion semantics.
Friend Class ConversionResolution
Friend NotInheritable Class ConversionResolution
' Prevent creation.
Private Sub New()
End Sub
Expand Down Expand Up @@ -1011,7 +1011,7 @@ Namespace Microsoft.VisualBasic.CompilerServices

End Function

Friend Class OperatorCaches
Friend NotInheritable Class OperatorCaches
' Prevent creation.
Private Sub New()
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Imports Microsoft.VisualBasic.CompilerServices.Symbols
Namespace Microsoft.VisualBasic.CompilerServices

' Implements VB late binder for IDynamicMetaObjectProvider.
Friend Class IDOBinder
Friend NotInheritable Class IDOBinder

Friend Const UnsafeSubclassCtorMessage As String = "This subclass is unsafe. Marking ctor unsafe in order to suppress warnings for overridden methods as unsafe."
Friend Const SuppressionJustification As String = "The constructor of this subclass has been annotated."
Expand Down Expand Up @@ -285,7 +285,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBCallBinder
Friend NotInheritable Class VBCallBinder
Inherits InvokeMemberBinder

Private ReadOnly _ignoreReturn As Boolean
Expand Down Expand Up @@ -369,7 +369,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBGetBinder
Friend NotInheritable Class VBGetBinder
Inherits InvokeMemberBinder

<RequiresUnreferencedCode(IDOBinder.UnsafeSubclassCtorMessage)>
Expand Down Expand Up @@ -449,7 +449,7 @@ Namespace Microsoft.VisualBasic.CompilerServices


' Implements FallbackInvoke for VBCallBinder and VBGetBinder
Friend Class VBInvokeBinder
Friend NotInheritable Class VBInvokeBinder
Inherits InvokeBinder

' True if this is coming from LateCall, false if it's for LateGet
Expand Down Expand Up @@ -524,7 +524,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBInvokeDefaultBinder
Friend NotInheritable Class VBInvokeDefaultBinder
Inherits InvokeBinder

Private ReadOnly _reportErrors As Boolean
Expand Down Expand Up @@ -593,7 +593,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBInvokeDefaultFallbackBinder
Friend NotInheritable Class VBInvokeDefaultFallbackBinder
Inherits GetIndexBinder

Private ReadOnly _reportErrors As Boolean
Expand Down Expand Up @@ -662,7 +662,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBSetBinder
Friend NotInheritable Class VBSetBinder
Inherits SetMemberBinder

<RequiresUnreferencedCode(IDOBinder.UnsafeSubclassCtorMessage)>
Expand Down Expand Up @@ -714,7 +714,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBSetComplexBinder
Friend NotInheritable Class VBSetComplexBinder
Inherits SetMemberBinder

Private ReadOnly _optimisticSet As Boolean
Expand Down Expand Up @@ -774,7 +774,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Class

' Used to fetch a DLR field
Friend Class VBGetMemberBinder
Friend NotInheritable Class VBGetMemberBinder
Inherits GetMemberBinder
Implements IInvokeOnGetBinder
Public Sub New(ByVal name As String)
Expand Down Expand Up @@ -814,7 +814,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Property
End Class

Friend Class VBConversionBinder
Friend NotInheritable Class VBConversionBinder
Inherits ConvertBinder

<RequiresUnreferencedCode(IDOBinder.UnsafeSubclassCtorMessage)>
Expand Down Expand Up @@ -862,7 +862,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBUnaryOperatorBinder
Friend NotInheritable Class VBUnaryOperatorBinder
Inherits UnaryOperationBinder

Private ReadOnly _Op As UserDefinedOperator
Expand Down Expand Up @@ -910,7 +910,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBBinaryOperatorBinder
Friend NotInheritable Class VBBinaryOperatorBinder
Inherits BinaryOperationBinder

Private ReadOnly _Op As UserDefinedOperator
Expand Down Expand Up @@ -961,7 +961,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBIndexSetBinder
Friend NotInheritable Class VBIndexSetBinder
Inherits SetIndexBinder

<RequiresUnreferencedCode(IDOBinder.UnsafeSubclassCtorMessage)>
Expand Down Expand Up @@ -1029,7 +1029,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class VBIndexSetComplexBinder
Friend NotInheritable Class VBIndexSetComplexBinder
Inherits SetIndexBinder

Private ReadOnly _optimisticSet As Boolean
Expand Down Expand Up @@ -1104,7 +1104,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function
End Class

Friend Class IDOUtils
Friend NotInheritable Class IDOUtils

Private Sub New()
Throw New InternalErrorException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils

Namespace Microsoft.VisualBasic.CompilerServices

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)> _
Class IOUtils
<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
NotInheritable Class IOUtils
' Prevent creation.
Private Sub New()
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Imports System.Diagnostics.CodeAnalysis
Namespace Microsoft.VisualBasic.CompilerServices

' Implements VB method overloading semantics.
Friend Class OverloadResolution
Friend NotInheritable Class OverloadResolution
' Prevent creation.
Private Sub New()
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Interface

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
Friend Class StructUtils
Friend NotInheritable Class StructUtils
' Prevent creation.
Private Sub New()
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Namespace Microsoft.VisualBasic.CompilerServices

' The symbol table. This consists of helper functions wrapping Reflection
' (which is the actual "symbol table").
Friend Class Symbols
Friend NotInheritable Class Symbols
' Prevent creation.
Private Sub New()
End Sub
Expand Down Expand Up @@ -748,7 +748,7 @@ Namespace Microsoft.VisualBasic.CompilerServices

Friend NotInheritable Class Container

Private Class InheritanceSorter : Implements IComparer(Of MemberInfo)
Private NotInheritable Class InheritanceSorter : Implements IComparer(Of MemberInfo)

Private Sub New()
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Imports System.Diagnostics.CodeAnalysis
Namespace Microsoft.VisualBasic.CompilerServices

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
Friend Class VB6BinaryFile
Friend NotInheritable Class VB6BinaryFile

'============================================================================
' Declarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Imports System.Diagnostics.CodeAnalysis
Namespace Microsoft.VisualBasic.CompilerServices

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
Friend Class VB6InputFile
Friend NotInheritable Class VB6InputFile

'============================================================================
' Declarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Imports Microsoft.VisualBasic.CompilerServices.Utils
Namespace Microsoft.VisualBasic.CompilerServices

<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
Friend Class VB6OutputFile
Friend NotInheritable Class VB6OutputFile

'============================================================================
' Declarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ Namespace Microsoft.VisualBasic.FileIO
''' <summary>
''' A simple tree node to build up the directory structure used for a snapshot in Copy / Move Directory.
''' </summary>
Private Class DirectoryNode
Private NotInheritable Class DirectoryNode
''' <summary>
''' Given a DirectoryPath, create the node and add the sub-directory nodes.
''' </summary>
Expand Down Expand Up @@ -2083,7 +2083,7 @@ Namespace Microsoft.VisualBasic.FileIO
''' This class will take care of text spanning byte arrays by caching a part of the array and use it in
''' the next IsTextFound() call.
''' </remarks>
Private Class TextSearchHelper
Private NotInheritable Class TextSearchHelper
''' <summary>
''' Constructs a new helper with a given encoding and a text to search for.
''' </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ Namespace Microsoft.VisualBasic.FileIO
''' will build the field and handle escaped quotes
''' </summary>
''' <remarks></remarks>
Friend Class QuoteDelimitedFieldBuilder
Friend NotInheritable Class QuoteDelimitedFieldBuilder
''' <summary>
''' Creates an instance of the class and sets some properties
''' </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static void SerializeWithBinaryFormatter(Stream o, string cryptoKey, Des
#pragma warning restore SYSLIB0011
}

private class StreamWrapper : Stream
private sealed class StreamWrapper : Stream
{
private Stream _stream;
private bool _readFirstByte;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public ConcurrentDictionary<TObjectSequence, TAggregator> GetLabelValuesDictiona
}
}

internal class MultiSizeLabelNameDictionary<TAggregator> where TAggregator : Aggregator
internal sealed class MultiSizeLabelNameDictionary<TAggregator> where TAggregator : Aggregator
{
private TAggregator? NoLabelAggregator;
private FixedSizeLabelNameDictionary<StringSequence1, ObjectSequence1, TAggregator>? Label1;
Expand Down Expand Up @@ -406,7 +406,7 @@ private static LabelInstruction[] Compile(ReadOnlySpan<KeyValuePair<string, obje
}

[System.Security.SecurityCritical] // using SecurityCritical type ReadOnlySpan
internal class LabelInstructionInterpretter<TObjectSequence, TAggregator>
internal sealed class LabelInstructionInterpretter<TObjectSequence, TAggregator>
where TObjectSequence : struct, IObjectSequence, IEquatable<TObjectSequence>
where TAggregator : Aggregator
{
Expand Down Expand Up @@ -477,7 +477,7 @@ public bool GetAggregator(
}
}

internal class FixedSizeLabelNameDictionary<TStringSequence, TObjectSequence, TAggregator> :
internal sealed class FixedSizeLabelNameDictionary<TStringSequence, TObjectSequence, TAggregator> :
ConcurrentDictionary<TStringSequence, ConcurrentDictionary<TObjectSequence, TAggregator>>
where TAggregator : Aggregator
where TStringSequence : IStringSequence, IEquatable<TStringSequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private string FormatQuantiles(QuantileValue[] quantiles)
}
}

private class MetricSpec
private sealed class MetricSpec
{
private const char MeterInstrumentSeparator = '\\';
public string MeterName { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private int GetShellError(IntPtr error)
}
}

internal unsafe class ShellExecuteHelper
internal sealed unsafe class ShellExecuteHelper
{
private readonly Interop.Shell32.SHELLEXECUTEINFO* _executeInfo;
private bool _succeeded;
Expand Down
Loading

0 comments on commit b320541

Please sign in to comment.