From 9ad6e6633fa2f2b54d07cb002d860e6e9acef827 Mon Sep 17 00:00:00 2001 From: Manodasan Wignarajah Date: Thu, 18 Nov 2021 11:28:14 -0800 Subject: [PATCH] Mark typed sealed where possible (#1050) * Mark types sealed when possible * Fix warning --- src/WinRT.Runtime/ComWrappersSupport.cs | 2 +- src/WinRT.Runtime/ComWrappersSupport.net5.cs | 2 +- .../ComWrappersSupport.netstandard2.0.cs | 4 ++-- src/WinRT.Runtime/ExceptionHelpers.cs | 4 ++-- src/WinRT.Runtime/Interop/ExceptionErrorInfo.cs | 2 +- src/WinRT.Runtime/Interop/IAgileReference.net5.cs | 2 +- .../Interop/IAgileReference.netstandard2.0.cs | 4 ++-- src/WinRT.Runtime/Interop/IContextCallback.cs | 2 +- src/WinRT.Runtime/Interop/IMarshal.cs | 2 +- .../Interop/IWeakReferenceSource.net5.cs | 2 +- .../Interop/IWeakReferenceSource.netstandard2.0.cs | 2 +- src/WinRT.Runtime/MonoSupport.cs | 4 ++-- src/WinRT.Runtime/ObjectReference.cs | 2 +- src/WinRT.Runtime/Projections/Bindable.net5.cs | 6 +++--- src/WinRT.Runtime/Projections/EventHandler.cs | 8 ++++---- src/WinRT.Runtime/Projections/Geometry.cs | 2 +- .../Projections/ICustomPropertyProvider.net5.cs | 4 ++-- .../ICustomPropertyProvider.netstandard2.0.cs | 4 ++-- src/WinRT.Runtime/Projections/IDictionary.net5.cs | 4 ++-- src/WinRT.Runtime/Projections/IEnumerable.net5.cs | 2 +- src/WinRT.Runtime/Projections/IList.net5.cs | 2 +- src/WinRT.Runtime/Projections/IPropertyValue.net5.cs | 2 +- .../Projections/IPropertyValue.netstandard2.0.cs | 2 +- .../Projections/IReadOnlyDictionary.net5.cs | 6 +++--- .../IReadOnlyDictionary.netstandard2.0.cs | 2 +- src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs | 2 +- .../Projections/IReferenceArray.net5.cs | 2 +- .../Projections/IReferenceArray.netstandard2.0.cs | 2 +- .../Projections/NotifyCollectionChangedEventArgs.cs | 2 +- .../NotifyCollectionChangedEventHandler.cs | 4 ++-- .../Projections/PropertyChangedEventHandler.cs | 4 ++-- src/cswinrt/code_writers.h | 12 ++++++------ src/cswinrt/strings/WinRT_Interop.cs | 3 ++- .../Microsoft.UI.Xaml/Microsoft.UI.Xaml.SR.cs | 2 +- .../Windows.Foundation/TaskToAsyncActionAdapter.cs | 4 ++-- .../TaskToAsyncActionWithProgressAdapter.cs | 4 ++-- .../TaskToAsyncOperationAdapter.cs | 4 ++-- .../TaskToAsyncOperationWithProgressAdapter.cs | 4 ++-- .../Windows.Foundation/Windows.Foundation.SR.cs | 2 +- .../additions/Windows.Storage.Streams/IMarshal.cs | 2 +- .../NetFxToWinRtStreamAdapter.cs | 8 ++++---- .../StreamOperationAsyncResult.cs | 6 +++--- .../WinRtToNetFxStreamAdapter.cs | 2 +- .../Windows.Storage.Streams.SR.cs | 2 +- .../WindowsRuntimeBufferExtensions.cs | 2 +- .../additions/Windows.Storage/Windows.Storage.SR.cs | 2 +- 46 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/WinRT.Runtime/ComWrappersSupport.cs b/src/WinRT.Runtime/ComWrappersSupport.cs index 8068b3913..21aeff3a6 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.cs @@ -768,7 +768,7 @@ private static ComInterfaceEntry ProvideIReferenceArray(Type arrayType) }; } - internal class InspectableInfo + internal sealed class InspectableInfo { private readonly Lazy runtimeClassName; diff --git a/src/WinRT.Runtime/ComWrappersSupport.net5.cs b/src/WinRT.Runtime/ComWrappersSupport.net5.cs index c8c73990b..5a61332bf 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -551,7 +551,7 @@ protected override void ReleaseObjects(IEnumerable objects) } } - unsafe class VtableEntries + unsafe sealed class VtableEntries { public ComInterfaceEntry* Data { get; } public int Count { get; } diff --git a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs index 5366e69bf..04a02bc56 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs @@ -214,7 +214,7 @@ private static uint Do_Abi_Release(IntPtr pThis) return UnmanagedObject.FindObject(pThis).Release(); } - private class RuntimeWrapperCleanup + private sealed class RuntimeWrapperCleanup { public IntPtr _identityComObject; public System.WeakReference _runtimeWrapper; @@ -303,7 +303,7 @@ internal static T FindObject(IntPtr thisPtr) } } - internal class ComCallableWrapper + internal sealed class ComCallableWrapper { private Dictionary _managedQITable; private GCHandle _qiTableHandle; diff --git a/src/WinRT.Runtime/ExceptionHelpers.cs b/src/WinRT.Runtime/ExceptionHelpers.cs index 15a416067..dd1a64582 100644 --- a/src/WinRT.Runtime/ExceptionHelpers.cs +++ b/src/WinRT.Runtime/ExceptionHelpers.cs @@ -259,7 +259,7 @@ public static int GetHRForException(Exception ex) // the exception instance in the app to hold the error object alive. // [Serializable] - internal class __RestrictedErrorObject + internal sealed class __RestrictedErrorObject { // Hold the error object instance but don't serialize/deserialize it [NonSerialized] @@ -404,7 +404,7 @@ internal static Exception GetExceptionForHR(this Exception innerException, int h } } - internal class ErrorStrings + internal static class ErrorStrings { internal static string Format(string format, params object[] args) => String.Format(format, args); diff --git a/src/WinRT.Runtime/Interop/ExceptionErrorInfo.cs b/src/WinRT.Runtime/Interop/ExceptionErrorInfo.cs index 33f1a32a1..775c62b73 100644 --- a/src/WinRT.Runtime/Interop/ExceptionErrorInfo.cs +++ b/src/WinRT.Runtime/Interop/ExceptionErrorInfo.cs @@ -51,7 +51,7 @@ void GetErrorDetails( string GetReference(); } - internal class ManagedExceptionErrorInfo : IErrorInfo, ISupportErrorInfo + internal sealed class ManagedExceptionErrorInfo : IErrorInfo, ISupportErrorInfo { private readonly Exception _exception; diff --git a/src/WinRT.Runtime/Interop/IAgileReference.net5.cs b/src/WinRT.Runtime/Interop/IAgileReference.net5.cs index 6dac712bc..29ac3a408 100644 --- a/src/WinRT.Runtime/Interop/IAgileReference.net5.cs +++ b/src/WinRT.Runtime/Interop/IAgileReference.net5.cs @@ -141,7 +141,7 @@ static Vftbl() } [Guid("00000146-0000-0000-C000-000000000046")] - internal unsafe class IGlobalInterfaceTable : global::WinRT.Interop.IGlobalInterfaceTable + internal sealed unsafe class IGlobalInterfaceTable : global::WinRT.Interop.IGlobalInterfaceTable { [Guid("00000146-0000-0000-C000-000000000046")] [StructLayout(LayoutKind.Sequential)] diff --git a/src/WinRT.Runtime/Interop/IAgileReference.netstandard2.0.cs b/src/WinRT.Runtime/Interop/IAgileReference.netstandard2.0.cs index cf03b8911..5a7558f5c 100644 --- a/src/WinRT.Runtime/Interop/IAgileReference.netstandard2.0.cs +++ b/src/WinRT.Runtime/Interop/IAgileReference.netstandard2.0.cs @@ -39,7 +39,7 @@ namespace ABI.WinRT.Interop using global::WinRT; [Guid("C03F6A43-65A4-9818-987E-E0B810D2A6F2")] - internal unsafe class IAgileReference : global::WinRT.Interop.IAgileReference + internal sealed unsafe class IAgileReference : global::WinRT.Interop.IAgileReference { [Guid("C03F6A43-65A4-9818-987E-E0B810D2A6F2")] public struct Vftbl @@ -162,7 +162,7 @@ public IAgileObject(ObjectReference obj) } [Guid("00000146-0000-0000-C000-000000000046")] - internal unsafe class IGlobalInterfaceTable : global::WinRT.Interop.IGlobalInterfaceTable + internal sealed unsafe class IGlobalInterfaceTable : global::WinRT.Interop.IGlobalInterfaceTable { [Guid("00000146-0000-0000-C000-000000000046")] [StructLayout(LayoutKind.Sequential)] diff --git a/src/WinRT.Runtime/Interop/IContextCallback.cs b/src/WinRT.Runtime/Interop/IContextCallback.cs index a1ef1e0a7..9044239d8 100644 --- a/src/WinRT.Runtime/Interop/IContextCallback.cs +++ b/src/WinRT.Runtime/Interop/IContextCallback.cs @@ -37,7 +37,7 @@ void ContextCallback( namespace ABI.WinRT.Interop { [Guid("000001da-0000-0000-C000-000000000046")] - unsafe class IContextCallback : global::WinRT.Interop.IContextCallback + internal sealed unsafe class IContextCallback : global::WinRT.Interop.IContextCallback { [Guid("000001da-0000-0000-C000-000000000046")] public struct Vftbl diff --git a/src/WinRT.Runtime/Interop/IMarshal.cs b/src/WinRT.Runtime/Interop/IMarshal.cs index 7e1eca0ce..89928cec1 100644 --- a/src/WinRT.Runtime/Interop/IMarshal.cs +++ b/src/WinRT.Runtime/Interop/IMarshal.cs @@ -33,7 +33,7 @@ internal interface IMarshal namespace ABI.WinRT.Interop { [Guid("00000003-0000-0000-c000-000000000046")] - internal class IMarshal + internal sealed class IMarshal { internal static readonly Guid IID = new(0x00000003, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46); diff --git a/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs b/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs index 06c546c24..c651b8e5c 100644 --- a/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs +++ b/src/WinRT.Runtime/Interop/IWeakReferenceSource.net5.cs @@ -32,7 +32,7 @@ interface IWeakReference IObjectReference Resolve(Guid riid); } - internal class ManagedWeakReference : IWeakReference + internal sealed class ManagedWeakReference : IWeakReference { private readonly WeakReference _ref; public ManagedWeakReference(object obj) diff --git a/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs b/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs index 89dd03c61..24b447089 100644 --- a/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs +++ b/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs @@ -30,7 +30,7 @@ interface IWeakReference IObjectReference Resolve(Guid riid); } - internal class ManagedWeakReference : IWeakReference + internal sealed class ManagedWeakReference : IWeakReference { private WeakReference _ref; public ManagedWeakReference(object obj) diff --git a/src/WinRT.Runtime/MonoSupport.cs b/src/WinRT.Runtime/MonoSupport.cs index 8a9432c00..58a6a265c 100644 --- a/src/WinRT.Runtime/MonoSupport.cs +++ b/src/WinRT.Runtime/MonoSupport.cs @@ -10,7 +10,7 @@ namespace WinRT { - internal class Mono + internal static class Mono { static Lazy _usingMono = new Lazy(() => { @@ -72,7 +72,7 @@ struct MonoInternalThread_x64 public MonoThreadFlag flags; } - public class ThreadContext : IDisposable + public sealed class ThreadContext : IDisposable { static Lazy> _foreignThreads = new Lazy>(); diff --git a/src/WinRT.Runtime/ObjectReference.cs b/src/WinRT.Runtime/ObjectReference.cs index 5a8d9fffe..2a45fe2d2 100644 --- a/src/WinRT.Runtime/ObjectReference.cs +++ b/src/WinRT.Runtime/ObjectReference.cs @@ -444,7 +444,7 @@ private protected virtual T GetVftblForCurrentContext() } } - internal class ObjectReferenceWithContext : ObjectReference + internal sealed class ObjectReferenceWithContext : ObjectReference { private readonly IntPtr _contextCallbackPtr; private readonly IntPtr _contextToken; diff --git a/src/WinRT.Runtime/Projections/Bindable.net5.cs b/src/WinRT.Runtime/Projections/Bindable.net5.cs index 3b2bd78f6..0c8fa77bb 100644 --- a/src/WinRT.Runtime/Projections/Bindable.net5.cs +++ b/src/WinRT.Runtime/Projections/Bindable.net5.cs @@ -422,7 +422,7 @@ internal unsafe interface IEnumerable : global::System.Collections.IEnumerable, { public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IEnumerable)); - public class AdaptiveFromAbiHelper : FromAbiHelper, global::System.Collections.IEnumerable + public sealed class AdaptiveFromAbiHelper : FromAbiHelper, global::System.Collections.IEnumerable { private readonly Func _enumerator; @@ -480,7 +480,7 @@ private sealed class NonGenericToGenericIterator : global::Windows.Foundation.Co } } - public class ToAbiHelper : IBindableIterable + public sealed class ToAbiHelper : IBindableIterable { private readonly IEnumerable m_enumerable; @@ -596,7 +596,7 @@ unsafe interface IList : global::System.Collections.IList, global::Microsoft.UI. { public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IList)); - public class FromAbiHelper : global::System.Collections.IList + public sealed class FromAbiHelper : global::System.Collections.IList { private readonly global::Microsoft.UI.Xaml.Interop.IBindableVector _vector; diff --git a/src/WinRT.Runtime/Projections/EventHandler.cs b/src/WinRT.Runtime/Projections/EventHandler.cs index 4d73a9655..ca0e5ca4f 100644 --- a/src/WinRT.Runtime/Projections/EventHandler.cs +++ b/src/WinRT.Runtime/Projections/EventHandler.cs @@ -57,9 +57,9 @@ public static IntPtr GetAbi(IObjectReference value) => [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET - private class NativeDelegateWrapper + private sealed class NativeDelegateWrapper #else - private class NativeDelegateWrapper : IWinRTObject + private sealed class NativeDelegateWrapper : IWinRTObject #endif { private readonly ObjectReference _nativeDelegate; @@ -187,9 +187,9 @@ public static IntPtr GetAbi(IObjectReference value) => [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET - private class NativeDelegateWrapper + private sealed class NativeDelegateWrapper #else - private class NativeDelegateWrapper : IWinRTObject + private sealed class NativeDelegateWrapper : IWinRTObject #endif { private readonly ObjectReference _nativeDelegate; diff --git a/src/WinRT.Runtime/Projections/Geometry.cs b/src/WinRT.Runtime/Projections/Geometry.cs index be50c1d76..e7ace5436 100644 --- a/src/WinRT.Runtime/Projections/Geometry.cs +++ b/src/WinRT.Runtime/Projections/Geometry.cs @@ -7,7 +7,7 @@ namespace Windows.Foundation { - internal class GSR + internal static class GSR { public static string ArgumentOutOfRange_NeedNonNegNum = "Non-negative number required."; } diff --git a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs index a48aa44e6..22440797b 100644 --- a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs +++ b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs @@ -26,7 +26,7 @@ interface ICustomProperty namespace ABI.Microsoft.UI.Xaml.Data { [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] - internal unsafe class ICustomProperty + internal sealed unsafe class ICustomProperty { [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] public struct Vftbl @@ -234,7 +234,7 @@ internal static class ICustomProperty_Delegates public unsafe delegate int get_CanRead_7(IntPtr thisPtr, byte* value); } - internal class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty + internal sealed class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty { private readonly PropertyInfo _property; diff --git a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.netstandard2.0.cs b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.netstandard2.0.cs index 0b7229c16..cbf346f00 100644 --- a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.netstandard2.0.cs @@ -26,7 +26,7 @@ interface ICustomProperty namespace ABI.Microsoft.UI.Xaml.Data { [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] - internal unsafe class ICustomProperty + internal sealed unsafe class ICustomProperty { [Guid("30DA92C0-23E8-42A0-AE7C-734A0E5D2782")] public struct Vftbl @@ -220,7 +220,7 @@ internal static class ICustomProperty_Delegates public unsafe delegate int get_CanRead_7(IntPtr thisPtr, byte* value); } - internal class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty + internal sealed class ManagedCustomProperty : global::Microsoft.UI.Xaml.Data.ICustomProperty { private readonly PropertyInfo _property; diff --git a/src/WinRT.Runtime/Projections/IDictionary.net5.cs b/src/WinRT.Runtime/Projections/IDictionary.net5.cs index 4b1259553..2b3020779 100644 --- a/src/WinRT.Runtime/Projections/IDictionary.net5.cs +++ b/src/WinRT.Runtime/Projections/IDictionary.net5.cs @@ -60,7 +60,7 @@ public static void DisposeAbi(IntPtr abi) => public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IDictionary)); - public class FromAbiHelper : global::System.Collections.Generic.IDictionary + public sealed class FromAbiHelper : global::System.Collections.Generic.IDictionary { private readonly global::Windows.Foundation.Collections.IMap _map; internal readonly Dictionary _lookupCache = new(); @@ -438,7 +438,7 @@ public void Reset() } } - public class ToAbiHelper : global::Windows.Foundation.Collections.IMap + public sealed class ToAbiHelper : global::Windows.Foundation.Collections.IMap { private readonly global::System.Collections.Generic.IDictionary _dictionary; diff --git a/src/WinRT.Runtime/Projections/IEnumerable.net5.cs b/src/WinRT.Runtime/Projections/IEnumerable.net5.cs index 23f645f3f..0769dab29 100644 --- a/src/WinRT.Runtime/Projections/IEnumerable.net5.cs +++ b/src/WinRT.Runtime/Projections/IEnumerable.net5.cs @@ -69,7 +69,7 @@ public static void DisposeAbi(IntPtr abi) => public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IEnumerable)); - public class FromAbiHelper : global::System.Collections.Generic.IEnumerable + public sealed class FromAbiHelper : global::System.Collections.Generic.IEnumerable { private readonly global::System.Collections.Generic.IEnumerable _iterable; diff --git a/src/WinRT.Runtime/Projections/IList.net5.cs b/src/WinRT.Runtime/Projections/IList.net5.cs index bf2804bdf..bc7789d4a 100644 --- a/src/WinRT.Runtime/Projections/IList.net5.cs +++ b/src/WinRT.Runtime/Projections/IList.net5.cs @@ -60,7 +60,7 @@ public static void DisposeAbi(IntPtr abi) => public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IList)); - public class FromAbiHelper : global::System.Collections.Generic.IList + public sealed class FromAbiHelper : global::System.Collections.Generic.IList { private readonly global::Windows.Foundation.Collections.IVector _vector; diff --git a/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs b/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs index 06ad877b5..6a0988921 100644 --- a/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs +++ b/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs @@ -209,7 +209,7 @@ private static T UnboxValue(object value) } #pragma warning disable CS0649 - private class Boxed + private sealed class Boxed where T : struct { public T Value; diff --git a/src/WinRT.Runtime/Projections/IPropertyValue.netstandard2.0.cs b/src/WinRT.Runtime/Projections/IPropertyValue.netstandard2.0.cs index 7cd92283f..6f48ae56c 100644 --- a/src/WinRT.Runtime/Projections/IPropertyValue.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/IPropertyValue.netstandard2.0.cs @@ -211,7 +211,7 @@ private static T UnboxValue(object value) } #pragma warning disable CS0649 - private class Boxed + private sealed class Boxed where T : struct { public T Value; diff --git a/src/WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs b/src/WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs index 4b32e793c..41a0020aa 100644 --- a/src/WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs +++ b/src/WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs @@ -157,7 +157,7 @@ public void Reset() } } - public class FromAbiHelper : global::System.Collections.Generic.IReadOnlyDictionary + public sealed class FromAbiHelper : global::System.Collections.Generic.IReadOnlyDictionary { private readonly global::Windows.Foundation.Collections.IMapView _mapView; private readonly global::System.Collections.Generic.IEnumerable> _enumerable; @@ -258,7 +258,7 @@ private static V Lookup(global::Windows.Foundation.Collections.IMapView _t } - public class ToAbiHelper : global::Windows.Foundation.Collections.IMapView + public sealed class ToAbiHelper : global::Windows.Foundation.Collections.IMapView { private readonly global::System.Collections.Generic.IReadOnlyDictionary _dictionary; @@ -305,7 +305,7 @@ public V Lookup(K key) private sealed class ConstantSplittableMap : global::Windows.Foundation.Collections.IMapView, global::System.Collections.Generic.IReadOnlyDictionary { - private class KeyValuePairComparator : IComparer> + private sealed class KeyValuePairComparator : IComparer> { private static readonly IComparer keyComparator = Comparer.Default; diff --git a/src/WinRT.Runtime/Projections/IReadOnlyDictionary.netstandard2.0.cs b/src/WinRT.Runtime/Projections/IReadOnlyDictionary.netstandard2.0.cs index c5799d274..1e321c5ad 100644 --- a/src/WinRT.Runtime/Projections/IReadOnlyDictionary.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/IReadOnlyDictionary.netstandard2.0.cs @@ -320,7 +320,7 @@ public V Lookup(K key) private sealed class ConstantSplittableMap : global::Windows.Foundation.Collections.IMapView, global::System.Collections.Generic.IReadOnlyDictionary { - private class KeyValuePairComparator : IComparer> + private sealed class KeyValuePairComparator : IComparer> { private static readonly IComparer keyComparator = Comparer.Default; diff --git a/src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs b/src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs index 669692c83..24bf085bf 100644 --- a/src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs +++ b/src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs @@ -50,7 +50,7 @@ public static void DisposeAbi(IntPtr abi) => public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IReadOnlyList)); - public class FromAbiHelper : global::System.Collections.Generic.IReadOnlyList + public sealed class FromAbiHelper : global::System.Collections.Generic.IReadOnlyList { private readonly global::Windows.Foundation.Collections.IVectorView _vectorView; private readonly global::System.Collections.Generic.IEnumerable _enumerable; diff --git a/src/WinRT.Runtime/Projections/IReferenceArray.net5.cs b/src/WinRT.Runtime/Projections/IReferenceArray.net5.cs index 71b508056..7d70e4ae4 100644 --- a/src/WinRT.Runtime/Projections/IReferenceArray.net5.cs +++ b/src/WinRT.Runtime/Projections/IReferenceArray.net5.cs @@ -61,7 +61,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, out int ____return_ [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] [Guid("61C17707-2D65-11E0-9AE8-D48564015472")] - internal class IReferenceArray : global::Windows.Foundation.IReferenceArray + internal sealed class IReferenceArray : global::Windows.Foundation.IReferenceArray { public static IObjectReference CreateMarshaler(object value) { diff --git a/src/WinRT.Runtime/Projections/IReferenceArray.netstandard2.0.cs b/src/WinRT.Runtime/Projections/IReferenceArray.netstandard2.0.cs index 52f4d8e84..f8403ddcc 100644 --- a/src/WinRT.Runtime/Projections/IReferenceArray.netstandard2.0.cs +++ b/src/WinRT.Runtime/Projections/IReferenceArray.netstandard2.0.cs @@ -61,7 +61,7 @@ private static unsafe int Do_Abi_get_Value_0(IntPtr thisPtr, out int ____return_ [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] [Guid("61C17707-2D65-11E0-9AE8-D48564015472")] - internal class IReferenceArray : global::Windows.Foundation.IReferenceArray + internal sealed class IReferenceArray : global::Windows.Foundation.IReferenceArray { public static IObjectReference CreateMarshaler(object value) { diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs index 1adc51583..3dab26ffc 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs @@ -111,7 +111,7 @@ public unsafe int OldStartingIndex [global::WinRT.ObjectReferenceWrapper(nameof(_obj))] [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] - internal unsafe sealed class WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory + internal sealed unsafe class WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory { [Guid("5108EBA4-4892-5A20-8374-A96815E0FD27")] [StructLayout(LayoutKind.Sequential)] diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs index 04f0e8d63..025aef452 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs @@ -58,9 +58,9 @@ public static unsafe IObjectReference CreateMarshaler(global::System.Collections [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET - private class NativeDelegateWrapper + private sealed class NativeDelegateWrapper #else - private class NativeDelegateWrapper : IWinRTObject + private sealed class NativeDelegateWrapper : IWinRTObject #endif { private readonly ObjectReference _nativeDelegate; diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs index aa98ec787..998846cc8 100644 --- a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs @@ -57,9 +57,9 @@ public static unsafe IObjectReference CreateMarshaler(global::System.ComponentMo [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET - private class NativeDelegateWrapper + private sealed class NativeDelegateWrapper #else - private class NativeDelegateWrapper : IWinRTObject + private sealed class NativeDelegateWrapper : IWinRTObject #endif { private readonly ObjectReference _nativeDelegate; diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h index f982fc826..005ea6a6c 100644 --- a/src/cswinrt/code_writers.h +++ b/src/cswinrt/code_writers.h @@ -1800,7 +1800,7 @@ remove => %; factoryAs, cache_vftbl_type); w.write(R"( -internal class _% : ABI.%.% +internal sealed class _% : ABI.%.% { public _%() : base(%()) { } % @@ -1818,7 +1818,7 @@ internal static % Instance => _instance; else { w.write(R"( -internal class _% : IWinRTObject +internal sealed class _% : IWinRTObject { private IObjectReference _obj; public _%() @@ -3689,7 +3689,7 @@ public unsafe % %(%) cache_vftbl_type); w.write(R"( -internal class _% : ABI.%.% +internal sealed class _% : ABI.%.% { public _%() : base(%()) { } private static _% _instance = new _%(); @@ -3711,7 +3711,7 @@ internal static _% Instance => _instance; else { w.write(R"( -internal class _% : IWinRTObject +internal sealed class _% : IWinRTObject { private IObjectReference _obj; private IntPtr ThisPtr => _obj.ThisPtr; @@ -6328,9 +6328,9 @@ return abiDelegate is null ? null : (%)ComWrappersSupport.TryRegisterObjectForIn [global::WinRT.ObjectReferenceWrapper(nameof(_nativeDelegate))] #if !NET -private class NativeDelegateWrapper +private sealed class NativeDelegateWrapper #else -private class NativeDelegateWrapper : IWinRTObject +private sealed class NativeDelegateWrapper : IWinRTObject #endif { private readonly ObjectReference _nativeDelegate; diff --git a/src/cswinrt/strings/WinRT_Interop.cs b/src/cswinrt/strings/WinRT_Interop.cs index 8c99f5071..ad5e06b11 100644 --- a/src/cswinrt/strings/WinRT_Interop.cs +++ b/src/cswinrt/strings/WinRT_Interop.cs @@ -27,7 +27,8 @@ internal struct IDelegateVftbl public IntPtr Invoke; } - [Guid("64BD43F8-bFEE-4EC4-B7EB-2935158DAE21")] + [Guid("64BD43F8-bFEE-4EC4-B7EB-2935158DAE21")] + [StructLayout(LayoutKind.Sequential)] internal unsafe struct IReferenceTrackerTargetVftbl { public global::WinRT.Interop.IUnknownVftbl IUnknownVftbl; diff --git a/src/cswinrt/strings/additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.SR.cs b/src/cswinrt/strings/additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.SR.cs index f70d94ac0..b0667a14d 100644 --- a/src/cswinrt/strings/additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.SR.cs +++ b/src/cswinrt/strings/additions/Microsoft.UI.Xaml/Microsoft.UI.Xaml.SR.cs @@ -4,7 +4,7 @@ namespace Microsoft.UI.Xaml { - class SR + static class SR { public static string DirectUI_CornerRadius_InvalidMember = "Invalid value for {0} property on CornerRadius."; public static string DirectUI_InvalidArgument = "Invalid argument."; diff --git a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionAdapter.cs b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionAdapter.cs index 9a3b96781..719d76571 100644 --- a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionAdapter.cs @@ -14,7 +14,7 @@ namespace System.Threading.Tasks #if NET [global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")] #endif - internal class TaskToAsyncActionAdapter + internal sealed class TaskToAsyncActionAdapter : TaskToAsyncInfoAdapter, IAsyncAction { @@ -41,7 +41,7 @@ internal TaskToAsyncActionAdapter(bool isCanceled) } - public virtual void GetResults() + public void GetResults() { GetResultsInternal(); } diff --git a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionWithProgressAdapter.cs b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionWithProgressAdapter.cs index 85971aedd..e0bfe7a97 100644 --- a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionWithProgressAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncActionWithProgressAdapter.cs @@ -14,7 +14,7 @@ namespace System.Threading.Tasks #if NET [global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")] #endif - internal class TaskToAsyncActionWithProgressAdapter + internal sealed class TaskToAsyncActionWithProgressAdapter : TaskToAsyncInfoAdapter, AsyncActionProgressHandler, VoidValueTypeParameter, @@ -47,7 +47,7 @@ internal TaskToAsyncActionWithProgressAdapter(bool isCanceled) } - public virtual void GetResults() + public void GetResults() { GetResultsInternal(); } diff --git a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationAdapter.cs b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationAdapter.cs index 23c216c1d..a86e1bc0c 100644 --- a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationAdapter.cs @@ -15,7 +15,7 @@ namespace System.Threading.Tasks #if NET [global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")] #endif - internal class TaskToAsyncOperationAdapter + internal sealed class TaskToAsyncOperationAdapter : TaskToAsyncInfoAdapter, VoidReferenceTypeParameter, TResult, VoidValueTypeParameter>, IAsyncOperation { @@ -39,7 +39,7 @@ internal TaskToAsyncOperationAdapter(TResult synchronousResult) { } - public virtual TResult GetResults() + public TResult GetResults() { return GetResultsInternal(); } diff --git a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationWithProgressAdapter.cs b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationWithProgressAdapter.cs index 450497719..6ff130b6b 100644 --- a/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationWithProgressAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Foundation/TaskToAsyncOperationWithProgressAdapter.cs @@ -15,7 +15,7 @@ namespace System.Threading.Tasks #if NET [global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")] #endif - internal class TaskToAsyncOperationWithProgressAdapter + internal sealed class TaskToAsyncOperationWithProgressAdapter : TaskToAsyncInfoAdapter, AsyncOperationProgressHandler, TResult, @@ -44,7 +44,7 @@ internal TaskToAsyncOperationWithProgressAdapter(TResult synchronousResult) { } - public virtual TResult GetResults() + public TResult GetResults() { return GetResultsInternal(); } diff --git a/src/cswinrt/strings/additions/Windows.Foundation/Windows.Foundation.SR.cs b/src/cswinrt/strings/additions/Windows.Foundation/Windows.Foundation.SR.cs index 8126e3645..506306e8d 100644 --- a/src/cswinrt/strings/additions/Windows.Foundation/Windows.Foundation.SR.cs +++ b/src/cswinrt/strings/additions/Windows.Foundation/Windows.Foundation.SR.cs @@ -4,7 +4,7 @@ namespace Windows.Foundation { - class SR + static class SR { public static string Argument_BufferLengthExceedsCapacity = "The specified useful data length exceeds the capacity of this buffer."; diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/IMarshal.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/IMarshal.cs index d56dc3d2e..bc005cfab 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/IMarshal.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/IMarshal.cs @@ -30,7 +30,7 @@ namespace ABI.Com using global::System.Runtime.InteropServices; [Guid("00000003-0000-0000-c000-000000000046")] - internal class IMarshal : global::Com.IMarshal + internal sealed class IMarshal : global::Com.IMarshal { [Guid("00000003-0000-0000-c000-000000000046")] public unsafe struct Vftbl diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/NetFxToWinRtStreamAdapter.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/NetFxToWinRtStreamAdapter.cs index 90fe7be96..ab78916a3 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/NetFxToWinRtStreamAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/NetFxToWinRtStreamAdapter.cs @@ -42,7 +42,7 @@ internal abstract class NetFxToWinRtStreamAdapter : IDisposable // The latter is much more elegant, and likely also faster. - private class InputStream : NetFxToWinRtStreamAdapter, IInputStream, IDisposable + private sealed class InputStream : NetFxToWinRtStreamAdapter, IInputStream, IDisposable { internal InputStream(Stream stream, StreamReadOperationOptimization readOptimization) : base(stream, readOptimization) @@ -51,7 +51,7 @@ internal InputStream(Stream stream, StreamReadOperationOptimization readOptimiza } - private class OutputStream : NetFxToWinRtStreamAdapter, IOutputStream, IDisposable + private sealed class OutputStream : NetFxToWinRtStreamAdapter, IOutputStream, IDisposable { internal OutputStream(Stream stream, StreamReadOperationOptimization readOptimization) : base(stream, readOptimization) @@ -60,7 +60,7 @@ internal OutputStream(Stream stream, StreamReadOperationOptimization readOptimiz } - private class RandomAccessStream : NetFxToWinRtStreamAdapter, IRandomAccessStream, IInputStream, IOutputStream, IDisposable + private sealed class RandomAccessStream : NetFxToWinRtStreamAdapter, IRandomAccessStream, IInputStream, IOutputStream, IDisposable { internal RandomAccessStream(Stream stream, StreamReadOperationOptimization readOptimization) : base(stream, readOptimization) @@ -69,7 +69,7 @@ internal RandomAccessStream(Stream stream, StreamReadOperationOptimization readO } - private class InputOutputStream : NetFxToWinRtStreamAdapter, IInputStream, IOutputStream, IDisposable + private sealed class InputOutputStream : NetFxToWinRtStreamAdapter, IInputStream, IOutputStream, IDisposable { internal InputOutputStream(Stream stream, StreamReadOperationOptimization readOptimization) : base(stream, readOptimization) diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/StreamOperationAsyncResult.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/StreamOperationAsyncResult.cs index 9bba024a1..1d916f226 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/StreamOperationAsyncResult.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/StreamOperationAsyncResult.cs @@ -293,7 +293,7 @@ private void ThrowWithIOExceptionDispatchInfo(Exception e) #region class StreamReadAsyncResult - internal class StreamReadAsyncResult : StreamOperationAsyncResult + internal sealed class StreamReadAsyncResult : StreamOperationAsyncResult { private readonly IBuffer _userBuffer; @@ -332,7 +332,7 @@ private void ProcessConcreteCompletedOperation(IAsyncOperationWithProgress asyncStreamWriteOperation, AsyncCallback userCompletionCallback, object userAsyncStateInfo, @@ -362,7 +362,7 @@ private void ProcessConcreteCompletedOperation(IAsyncOperationWithProgress asyncStreamFlushOperation, bool processCompletedOperationInCallback) diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/WinRtToNetFxStreamAdapter.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/WinRtToNetFxStreamAdapter.cs index fe410f4a6..35939e896 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/WinRtToNetFxStreamAdapter.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/WinRtToNetFxStreamAdapter.cs @@ -17,7 +17,7 @@ namespace Windows.Storage.Streams /// /// A Stream used to wrap a Windows Runtime stream to expose it as a managed steam. /// - internal class WinRtToNetFxStreamAdapter : Stream, IDisposable + internal sealed class WinRtToNetFxStreamAdapter : Stream, IDisposable { #region Construction diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/Windows.Storage.Streams.SR.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/Windows.Storage.Streams.SR.cs index 734df1bd9..7e781985e 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/Windows.Storage.Streams.SR.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/Windows.Storage.Streams.SR.cs @@ -4,7 +4,7 @@ namespace Windows.Storage.Streams { - class SR + static class SR { public static string Argument_BufferIndexExceedsCapacity = "The specified buffer index is not within the buffer capacity."; diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBufferExtensions.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBufferExtensions.cs index b069cd3e9..e38804e07 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBufferExtensions.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBufferExtensions.cs @@ -452,7 +452,7 @@ public static byte GetByte(this IBuffer source, uint byteOffset) #region Private plumbing - private class WindowsRuntimeBufferUnmanagedMemoryStream : UnmanagedMemoryStream + private sealed class WindowsRuntimeBufferUnmanagedMemoryStream : UnmanagedMemoryStream { // We need this class because if we construct an UnmanagedMemoryStream on an IBuffer backed by native memory, // we must keep around a reference to the IBuffer from which we got the memory pointer. Otherwise the ref count diff --git a/src/cswinrt/strings/additions/Windows.Storage/Windows.Storage.SR.cs b/src/cswinrt/strings/additions/Windows.Storage/Windows.Storage.SR.cs index 191365358..36ac34f14 100644 --- a/src/cswinrt/strings/additions/Windows.Storage/Windows.Storage.SR.cs +++ b/src/cswinrt/strings/additions/Windows.Storage/Windows.Storage.SR.cs @@ -4,7 +4,7 @@ namespace Windows.Storage { - class SR + static class SR { public static string Argument_BufferIndexExceedsCapacity = "The specified buffer index is not within the buffer capacity.";