From 4686d9195636f21d23a96f02571a0bc0b6ebe0bc Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Tue, 17 Sep 2024 22:08:28 +0200 Subject: [PATCH 1/3] Make classes sealed, methods static & avoid array allocations where possible, dispose disposable, other optimizations & clean up usings --- ref/Castle.Core-net462.cs | 15 ++++++------ ref/Castle.Core-net6.0.cs | 15 ++++++------ ref/Castle.Core-netstandard2.0.cs | 15 ++++++------ ref/Castle.Core-netstandard2.1.cs | 15 ++++++------ .../Attributes/RemoveIfAttribute.cs | 5 ++-- .../Attributes/RemoveIfEmptyAttribute.cs | 2 +- .../Attributes/StringListAttribute.cs | 3 +-- .../Attributes/XPathFunctionAttribute.cs | 2 +- .../DictionaryAdapterBase.Edit.cs | 3 +-- .../DictionaryAdapterBase.Notify.cs | 4 ++-- .../DictionaryAdapterFactory.cs | 1 - .../DictionaryAdapterInstance.cs | 2 +- .../GenericDictionaryAdapter.cs | 2 +- .../MemberwiseEqualityHashCodeStrategy.cs | 2 +- .../PropertyDescriptor.cs | 2 +- .../Util/BindingListInitializer.cs | 2 +- .../Xml/Core/XmlMetadata.cs | 3 +-- .../Xml/Core/XmlReferenceManager.cs | 9 +++---- .../Accessors/XPathBehaviorAccessor.cs | 4 ++-- .../Accessors/XmlArrayBehaviorAccessor.cs | 2 +- .../Accessors/XmlElementBehaviorAccessor.cs | 2 +- .../Xml/Internal/Accessors/XmlNodeAccessor.cs | 2 +- .../Collections/XmlCollectionAdapter.cs | 2 +- .../Xml/Internal/Collections/XmlNodeList.cs | 2 +- .../Xml/Internal/Collections/XmlNodeSet.cs | 2 +- .../Cursors/SystemXml/SysXmlCursor.cs | 7 +++--- .../Cursors/XPath/CompiledXPathNode.cs | 2 +- .../XPath/XPathBufferedNodeIterator.cs | 3 +-- .../Internal/Cursors/XPath/XPathCompiler.cs | 2 +- .../Internal/Cursors/XPath/XPathContext.cs | 2 +- .../Cursors/XPath/XPathMutableCursor.cs | 4 ++-- .../Serializers/XmlTypeSerializerCache.cs | 4 +--- .../Internal/Utilities/XmlSubtreeWriter.cs | 2 +- .../Core/Internal/InterfaceAttributeUtil.cs | 2 +- .../Core/Internal/InternalsVisible.cs | 2 +- .../Core/Internal/WeakKeyComparer.cs | 2 +- .../Core/Internal/WeakKeyDictionary.cs | 4 ++-- src/Castle.Core/Core/Logging/NullLogger.cs | 6 ++--- .../Core/Logging/TraceLoggerFactory.cs | 4 ++-- .../Core/ReflectionBasedDictionaryAdapter.cs | 2 +- .../Core/Resource/AssemblyResource.cs | 8 +++---- src/Castle.Core/Core/Resource/CustomUri.cs | 2 +- .../Core/StringObjectDictionaryAdapter.cs | 5 ++-- .../ClassProxyTargetContributor.cs | 5 ++-- .../ClassProxyWithTargetTargetContributor.cs | 6 ++--- .../Contributors/FieldReferenceComparer.cs | 2 +- .../Contributors/InterfaceMembersCollector.cs | 2 +- .../InterfaceMembersOnClassCollector.cs | 2 +- ...rfaceProxyWithOptionalTargetContributor.cs | 2 +- ...oxyWithTargetInterfaceTargetContributor.cs | 2 +- .../InvocationWithDelegateContributor.cs | 2 +- ...nvocationWithGenericDelegateContributor.cs | 5 ++-- .../Contributors/MixinContributor.cs | 3 +-- .../WrappedClassMembersCollector.cs | 7 +++--- .../DynamicProxy/CustomAttributeInfo.cs | 10 ++++---- .../DynamicProxy/DefaultProxyBuilder.cs | 8 +++---- .../Generators/BaseClassProxyGenerator.cs | 2 +- .../Generators/BaseInterfaceProxyGenerator.cs | 4 ++-- .../Generators/BaseProxyGenerator.cs | 24 +++++++++---------- .../DynamicProxy/Generators/CacheKey.cs | 2 +- .../CompositionInvocationTypeGenerator.cs | 2 +- .../Generators/DelegateTypeGenerator.cs | 5 ++-- .../Emitters/AbstractTypeEmitter.cs | 2 +- .../Generators/Emitters/ClassEmitter.cs | 4 ++-- .../Generators/Emitters/EventEmitter.cs | 2 +- .../Generators/Emitters/GenericUtil.cs | 3 +-- .../Generators/Emitters/MethodEmitter.cs | 12 ++++------ .../Generators/Emitters/NestedClassEmitter.cs | 2 +- .../Generators/Emitters/PropertyEmitter.cs | 2 +- .../Emitters/SimpleAST/ArgumentReference.cs | 2 +- .../Emitters/SimpleAST/AsTypeReference.cs | 2 +- .../SimpleAST/AssignArgumentStatement.cs | 2 +- .../SimpleAST/AssignArrayStatement.cs | 2 +- .../Emitters/SimpleAST/AssignStatement.cs | 2 +- .../Emitters/SimpleAST/BlockStatement.cs | 2 +- .../Emitters/SimpleAST/ByRefReference.cs | 2 +- .../ConstructorInvocationStatement.cs | 2 +- .../Emitters/SimpleAST/ConvertExpression.cs | 3 +-- .../SimpleAST/DefaultValueExpression.cs | 5 ++-- .../SimpleAST/EndExceptionBlockStatement.cs | 2 +- .../Emitters/SimpleAST/FieldReference.cs | 2 +- .../Emitters/SimpleAST/FinallyStatement.cs | 2 +- .../Emitters/SimpleAST/IfNullExpression.cs | 2 +- .../Emitters/SimpleAST/IndirectReference.cs | 3 +-- .../SimpleAST/LiteralBoolExpression.cs | 2 +- .../SimpleAST/LiteralIntExpression.cs | 2 +- .../SimpleAST/LiteralStringExpression.cs | 2 +- .../LoadRefArrayElementExpression.cs | 2 +- .../Emitters/SimpleAST/LocalReference.cs | 2 +- .../SimpleAST/MethodInvocationExpression.cs | 8 +++---- .../SimpleAST/MethodTokenExpression.cs | 2 +- .../Emitters/SimpleAST/NewArrayExpression.cs | 2 +- .../SimpleAST/NewInstanceExpression.cs | 2 +- .../NullCoalescingOperatorExpression.cs | 2 +- .../Emitters/SimpleAST/NullExpression.cs | 4 ++-- .../ReferencesToObjectArrayExpression.cs | 3 +-- .../Emitters/SimpleAST/ReturnStatement.cs | 2 +- .../Emitters/SimpleAST/SelfReference.cs | 4 ++-- .../Emitters/SimpleAST/ThrowStatement.cs | 3 +-- .../Emitters/SimpleAST/TryStatement.cs | 2 +- .../Emitters/SimpleAST/TypeTokenExpression.cs | 2 +- .../Emitters/TypeConstructorEmitter.cs | 2 +- .../Generators/ForwardingMethodGenerator.cs | 2 +- .../InheritanceInvocationTypeGenerator.cs | 2 +- .../InterfaceProxyWithTargetGenerator.cs | 2 +- .../Generators/InvocationTypeGenerator.cs | 6 ++--- .../DynamicProxy/Generators/MetaEvent.cs | 2 +- .../DynamicProxy/Generators/MetaMethod.cs | 2 +- .../DynamicProxy/Generators/MetaProperty.cs | 2 +- .../DynamicProxy/Generators/MetaType.cs | 2 +- .../Generators/MetaTypeElementCollection.cs | 2 +- .../Generators/MethodSignatureComparer.cs | 6 ++--- .../MethodWithInvocationGenerator.cs | 10 ++++---- .../Generators/MinimalisticMethodGenerator.cs | 4 ++-- .../DynamicProxy/Generators/NamingScope.cs | 2 +- .../OptionallyForwardingMethodGenerator.cs | 4 ++-- .../DynamicProxy/Internal/AttributeUtil.cs | 2 +- .../DynamicProxy/ProxyGenerationOptions.cs | 2 +- .../DynamicProxy/ProxyGenerator.cs | 24 +++++++++---------- 119 files changed, 215 insertions(+), 247 deletions(-) diff --git a/ref/Castle.Core-net462.cs b/ref/Castle.Core-net462.cs index a463161bc5..8215e3fa63 100644 --- a/ref/Castle.Core-net462.cs +++ b/ref/Castle.Core-net462.cs @@ -1945,11 +1945,10 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public class InternalsVisible + public static class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; - public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2680,10 +2679,6 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } - protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2699,7 +2694,6 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } - protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2743,7 +2737,12 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } + protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } + protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-net6.0.cs b/ref/Castle.Core-net6.0.cs index dd8a8652a4..23f83775e2 100644 --- a/ref/Castle.Core-net6.0.cs +++ b/ref/Castle.Core-net6.0.cs @@ -1939,11 +1939,10 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public class InternalsVisible + public static class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; - public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2637,10 +2636,6 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } - protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2656,7 +2651,6 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } - protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2700,7 +2694,12 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } + protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } + protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-netstandard2.0.cs b/ref/Castle.Core-netstandard2.0.cs index 53928d09b0..eb88539729 100644 --- a/ref/Castle.Core-netstandard2.0.cs +++ b/ref/Castle.Core-netstandard2.0.cs @@ -1939,11 +1939,10 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public class InternalsVisible + public static class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; - public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2634,10 +2633,6 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } - protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2653,7 +2648,6 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } - protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2697,7 +2691,12 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } + protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } + protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-netstandard2.1.cs b/ref/Castle.Core-netstandard2.1.cs index 40b01b56be..9849bf07cf 100644 --- a/ref/Castle.Core-netstandard2.1.cs +++ b/ref/Castle.Core-netstandard2.1.cs @@ -1939,11 +1939,10 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public class InternalsVisible + public static class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; - public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2634,10 +2633,6 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } - protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2653,7 +2648,6 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } - protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2697,7 +2691,12 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } + protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } + protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfAttribute.cs b/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfAttribute.cs index cf8da72a48..4b779e9eb5 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfAttribute.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfAttribute.cs @@ -17,7 +17,6 @@ namespace Castle.Components.DictionaryAdapter using System; using System.Linq; using System.Collections; - using System.Reflection; /// /// Removes a property if matches value. @@ -83,7 +82,7 @@ private static TBase Construct(Type type, string paramName) var constructor = type.GetConstructor(Type.EmptyTypes); if (constructor != null) { - return (TBase)constructor.Invoke(new object[0]); + return (TBase)constructor.Invoke(Array.Empty()); } } @@ -94,7 +93,7 @@ private static TBase Construct(Type type, string paramName) #region Nested Class: ValueCondition - class ValueCondition : ICondition + sealed class ValueCondition : ICondition { private readonly object[] values; private readonly IEqualityComparer comparer; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfEmptyAttribute.cs b/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfEmptyAttribute.cs index a1343ae44e..a7741edb53 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfEmptyAttribute.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Attributes/RemoveIfEmptyAttribute.cs @@ -29,7 +29,7 @@ public RemoveIfEmptyAttribute() private new Type Condition { get; set; } - class RemoveIfEmptyCondition : ICondition + sealed class RemoveIfEmptyCondition : ICondition { public static readonly RemoveIfEmptyCondition Instance = new RemoveIfEmptyCondition(); diff --git a/src/Castle.Core/Components.DictionaryAdapter/Attributes/StringListAttribute.cs b/src/Castle.Core/Components.DictionaryAdapter/Attributes/StringListAttribute.cs index bd8e99b319..4522b9f098 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Attributes/StringListAttribute.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Attributes/StringListAttribute.cs @@ -18,7 +18,6 @@ namespace Castle.Components.DictionaryAdapter using System.Collections; using System.Collections.Generic; using System.ComponentModel; - using System.Reflection; using System.Text; /// @@ -109,7 +108,7 @@ internal static string BuildString(IEnumerable enumerable, char separator) #region Nested Class: StringList - class StringListWrapper : IList + sealed class StringListWrapper : IList { private readonly string key; private readonly char separator; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Attributes/XPathFunctionAttribute.cs b/src/Castle.Core/Components.DictionaryAdapter/Attributes/XPathFunctionAttribute.cs index 19bf1a4c0c..92a7317529 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Attributes/XPathFunctionAttribute.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Attributes/XPathFunctionAttribute.cs @@ -31,7 +31,7 @@ protected XPathFunctionAttribute() { } public virtual int Minargs { get { return ArgTypes.Length; } } public static readonly XPathResultType[] - NoArgs = new XPathResultType[0]; + NoArgs = Array.Empty(); public abstract object Invoke(XsltContext context, object[] args, XPathNavigator node); } diff --git a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs index 7286aa1652..6ef4640081 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Edit.cs @@ -18,7 +18,6 @@ namespace Castle.Components.DictionaryAdapter using System.Collections.Generic; using System.ComponentModel; using System.Linq; - using System.Reflection; public abstract partial class DictionaryAdapterBase { @@ -223,7 +222,7 @@ protected void AddEditDependency(IEditableObject editDependency) #region Nested Class: SuppressEditingScope - class SuppressEditingScope : IDisposable + sealed class SuppressEditingScope : IDisposable { private readonly DictionaryAdapterBase adapter; diff --git a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs index 2b0262af49..6894fe7bb8 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterBase.Notify.cs @@ -106,7 +106,7 @@ protected TrackPropertyChangeScope TrackReadonlyPropertyChanges() return readOnlyTrackingScope = new TrackPropertyChangeScope(this); } - private class NotificationSuppressionScope : IDisposable + private sealed class NotificationSuppressionScope : IDisposable { private readonly DictionaryAdapterBase adapter; @@ -127,7 +127,7 @@ public class TrackPropertyChangeScope : IDisposable private readonly DictionaryAdapterBase adapter; private readonly PropertyDescriptor property; private readonly object existingValue; - private Dictionary readOnlyProperties; + private readonly Dictionary readOnlyProperties; public TrackPropertyChangeScope(DictionaryAdapterBase adapter) { diff --git a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterFactory.cs b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterFactory.cs index a2cb08a60d..33c55b934d 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterFactory.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterFactory.cs @@ -22,7 +22,6 @@ namespace Castle.Components.DictionaryAdapter using System.Linq; using System.Reflection; using System.Reflection.Emit; - using System.Threading; using System.Diagnostics; using Castle.Components.DictionaryAdapter.Xml; diff --git a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterInstance.cs b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterInstance.cs index e97b08af1d..9811b0e2a1 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterInstance.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/DictionaryAdapterInstance.cs @@ -149,6 +149,6 @@ private static IDictionary MergeProperties( } private static readonly IDictionaryInitializer[] - NoInitializers = { }; + NoInitializers = Array.Empty(); } } diff --git a/src/Castle.Core/Components.DictionaryAdapter/GenericDictionaryAdapter.cs b/src/Castle.Core/Components.DictionaryAdapter/GenericDictionaryAdapter.cs index 9780395113..f70619375a 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/GenericDictionaryAdapter.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/GenericDictionaryAdapter.cs @@ -33,7 +33,7 @@ public override bool IsReadOnly public override bool Contains(object key) { - return dictionary.Keys.Contains(GetKey(key)); + return dictionary.ContainsKey(GetKey(key)); } public override object this[object key] diff --git a/src/Castle.Core/Components.DictionaryAdapter/MemberwiseEqualityHashCodeStrategy.cs b/src/Castle.Core/Components.DictionaryAdapter/MemberwiseEqualityHashCodeStrategy.cs index ebfe611a89..240915b71a 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/MemberwiseEqualityHashCodeStrategy.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/MemberwiseEqualityHashCodeStrategy.cs @@ -21,7 +21,7 @@ namespace Castle.Components.DictionaryAdapter public class MemberwiseEqualityHashCodeStrategy : DictionaryBehaviorAttribute, IDictionaryEqualityHashCodeStrategy, IDictionaryInitializer, IEqualityComparer { - class HashCodeVisitor : AbstractDictionaryAdapterVisitor + sealed class HashCodeVisitor : AbstractDictionaryAdapterVisitor { private int hashCode; diff --git a/src/Castle.Core/Components.DictionaryAdapter/PropertyDescriptor.cs b/src/Castle.Core/Components.DictionaryAdapter/PropertyDescriptor.cs index 33055ce23c..3eeb30faa2 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/PropertyDescriptor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/PropertyDescriptor.cs @@ -33,7 +33,7 @@ public class PropertyDescriptor : IDictionaryKeyBuilder, IDictionaryPropertyGett private Dictionary extendedProperties; protected List dictionaryBehaviors; - private static readonly object[] NoAnnotations = new object[0]; + private static readonly object[] NoAnnotations = Array.Empty(); /// /// Initializes an empty class. diff --git a/src/Castle.Core/Components.DictionaryAdapter/Util/BindingListInitializer.cs b/src/Castle.Core/Components.DictionaryAdapter/Util/BindingListInitializer.cs index aba875439b..444af4403b 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Util/BindingListInitializer.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Util/BindingListInitializer.cs @@ -93,7 +93,7 @@ public void Initialize(IDictionaryAdapter dictionaryAdapter, object value) }; } - class SuppressListChangedEvents : IDisposable + sealed class SuppressListChangedEvents : IDisposable { private readonly bool raiseEvents; private readonly System.ComponentModel.BindingList bindingList; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlMetadata.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlMetadata.cs index f8919fe77a..8aa9124905 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlMetadata.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlMetadata.cs @@ -17,7 +17,6 @@ namespace Castle.Components.DictionaryAdapter.Xml using System; using System.Collections.Generic; using System.Linq; - using System.Reflection; using System.Xml; using System.Xml.Serialization; @@ -350,7 +349,7 @@ private XmlMetadata GetXmlMetadata(Type clrType) .GetXmlMeta(); } - private string GetDefaultTypeLocalName(Type clrType) + private static string GetDefaultTypeLocalName(Type clrType) { var name = clrType.Name; return IsInterfaceName(name) diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlReferenceManager.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlReferenceManager.cs index c325e7eaaf..c9cf8d340b 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlReferenceManager.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlReferenceManager.cs @@ -16,8 +16,6 @@ namespace Castle.Components.DictionaryAdapter.Xml { using System; using System.Collections.Generic; - using System.Linq; - using System.Reflection; using Castle.Core; using Castle.Core.Internal; @@ -372,7 +370,7 @@ private bool TryGetEntry(IXmlNode node, out Entry entry, out bool reference) return true; } - private bool TryGetCompatibleValue(Entry entry, Type type, ref object value) + private static bool TryGetCompatibleValue(Entry entry, Type type, ref object value) { var values = entry.Values; if (values == null) @@ -391,8 +389,7 @@ private bool TryGetCompatibleValue(Entry entry, Type type, ref object value) continue; if (type.IsAssignableFrom(item.Type)) - if (null != candidate) - return Try.Success(out value, candidate); + return Try.Success(out value, candidate); if (dictionaryAdapter == null) dictionaryAdapter = candidate as IDictionaryAdapter; @@ -483,7 +480,7 @@ private static readonly Type private static readonly object CreateEntryToken = new object(); - private class Entry + private sealed class Entry { public int Id; public IXmlNode Node; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XPathBehaviorAccessor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XPathBehaviorAccessor.cs index 72910aa91d..c492d91ca1 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XPathBehaviorAccessor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XPathBehaviorAccessor.cs @@ -180,7 +180,7 @@ public bool TryGet(Type clrType, out IXmlIncludedType includedType) : includedTypes.TryGet(clrType, out includedType); } - private class DefaultAccessor : XPathBehaviorAccessor + private sealed class DefaultAccessor : XPathBehaviorAccessor { private readonly XPathBehaviorAccessor parent; @@ -200,7 +200,7 @@ public override void Prepare() } } - private class ItemAccessor : XPathBehaviorAccessor + private sealed class ItemAccessor : XPathBehaviorAccessor { public ItemAccessor(XPathBehaviorAccessor parent) : base(parent.ClrType.GetCollectionItemType(), parent.Context) diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlArrayBehaviorAccessor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlArrayBehaviorAccessor.cs index c0a28aa7af..7c7873d36e 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlArrayBehaviorAccessor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlArrayBehaviorAccessor.cs @@ -64,7 +64,7 @@ public override IXmlCursor SelectPropertyNode(IXmlNode node, bool mutable) return node.SelectChildren(this, Context, PropertyFlags.MutableIf(mutable)); } - private class ItemAccessor : XmlNodeAccessor, + private sealed class ItemAccessor : XmlNodeAccessor, IConfigurable, IXmlBehaviorSemantics { diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlElementBehaviorAccessor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlElementBehaviorAccessor.cs index 750b2e4681..71eb157ac0 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlElementBehaviorAccessor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlElementBehaviorAccessor.cs @@ -96,7 +96,7 @@ public Type GetClrType(XmlElementAttribute attribute) return attribute.Type; } - private class ItemAccessor : XmlNodeAccessor + private sealed class ItemAccessor : XmlNodeAccessor { public ItemAccessor(XmlNodeAccessor parent) : base(parent.ClrType.GetCollectionItemType(), parent.Context) diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlNodeAccessor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlNodeAccessor.cs index 98515cd568..4df5d9a669 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlNodeAccessor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Accessors/XmlNodeAccessor.cs @@ -33,7 +33,7 @@ protected XmlNodeAccessor(string name, Type type, IXmlContext context) { if (name == null) throw Error.ArgumentNull(nameof(name)); - if (name == string.Empty) + if (name.Length == 0) throw Error.InvalidLocalName(); localName = XmlConvert.EncodeLocalName(name); diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlCollectionAdapter.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlCollectionAdapter.cs index 0b825e5d96..2323ff85df 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlCollectionAdapter.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlCollectionAdapter.cs @@ -17,7 +17,7 @@ namespace Castle.Components.DictionaryAdapter.Xml using System; using System.Collections.Generic; - internal class XmlCollectionAdapter : ICollectionAdapter, IXmlNodeSource + internal sealed class XmlCollectionAdapter : ICollectionAdapter, IXmlNodeSource { private List> items; private List> snapshot; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeList.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeList.cs index a66bbfd17f..efd7de21bb 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeList.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeList.cs @@ -14,7 +14,7 @@ namespace Castle.Components.DictionaryAdapter.Xml { - internal class XmlNodeList : ListProjection, IXmlNodeSource + internal sealed class XmlNodeList : ListProjection, IXmlNodeSource { public XmlNodeList ( diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeSet.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeSet.cs index efc47c8e18..416d9371ad 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeSet.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Collections/XmlNodeSet.cs @@ -14,7 +14,7 @@ namespace Castle.Components.DictionaryAdapter.Xml { - internal class XmlNodeSet : SetProjection, IXmlNodeSource + internal sealed class XmlNodeSet : SetProjection, IXmlNodeSource { public XmlNodeSet ( diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/SystemXml/SysXmlCursor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/SystemXml/SysXmlCursor.cs index 62fa949850..e06ce4af9f 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/SystemXml/SysXmlCursor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/SystemXml/SysXmlCursor.cs @@ -15,7 +15,6 @@ namespace Castle.Components.DictionaryAdapter.Xml { using System; - using System.Xml.XPath; using System.Xml; public class SysXmlCursor : SysXmlNode, IXmlCursor @@ -478,7 +477,7 @@ private void RequireNoXsiType(IXmlKnownType knownType) throw Error.CannotSetAttribute(this); } - private XmlName GetEffectiveName(IXmlKnownType knownType, XmlNode parent) + private static XmlName GetEffectiveName(IXmlKnownType knownType, XmlNode parent) { var name = knownType.Name; @@ -518,12 +517,12 @@ public void Remove() RemoveAttribute(removedNode); } - private void RemoveElement(XmlNode node) + private static void RemoveElement(XmlNode node) { node.ParentNode.RemoveChild(node); } - private void RemoveAttribute(XmlNode node) + private static void RemoveAttribute(XmlNode node) { var attribute = (XmlAttribute) node; attribute.OwnerElement.Attributes.Remove(attribute); diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/CompiledXPathNode.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/CompiledXPathNode.cs index a5a4748f7f..1c38bb75ff 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/CompiledXPathNode.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/CompiledXPathNode.cs @@ -84,7 +84,7 @@ public IList Dependencies } private static readonly IList - NoDependencies = Array.AsReadOnly(new CompiledXPathNode[0]); + NoDependencies = Array.AsReadOnly(Array.Empty()); private bool HasNoRealDependencies() { diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathBufferedNodeIterator.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathBufferedNodeIterator.cs index d310569927..2aa3073735 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathBufferedNodeIterator.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathBufferedNodeIterator.cs @@ -14,11 +14,10 @@ namespace Castle.Components.DictionaryAdapter.Xml { - using System; using System.Collections.Generic; using System.Xml.XPath; - internal class XPathBufferedNodeIterator : XPathNodeIterator + internal sealed class XPathBufferedNodeIterator : XPathNodeIterator { private readonly IList items; private int index; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathCompiler.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathCompiler.cs index 8a88dc4ce9..c09b1b06eb 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathCompiler.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathCompiler.cs @@ -310,7 +310,7 @@ private enum Token Error } - private class Tokenizer + private sealed class Tokenizer { private readonly string input; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathContext.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathContext.cs index 925b2168cb..b39de1f5d5 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathContext.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathContext.cs @@ -17,7 +17,7 @@ namespace Castle.Components.DictionaryAdapter.Xml using System.Xml.XPath; using System.Xml.Xsl; - internal class XPathContext : XsltContext + internal sealed class XPathContext : XsltContext { private readonly XsltContext context; diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathMutableCursor.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathMutableCursor.cs index 6d5e41f7d4..6ab2454b0f 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathMutableCursor.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Cursors/XPath/XPathMutableCursor.cs @@ -18,7 +18,7 @@ namespace Castle.Components.DictionaryAdapter.Xml using System.Xml; using System.Xml.XPath; - internal class XPathMutableCursor : XPathNode, IXmlCursor + internal sealed class XPathMutableCursor : XPathNode, IXmlCursor { private XPathBufferedNodeIterator iterator; private CompiledXPathStep step; @@ -214,7 +214,7 @@ public void MoveTo(IXmlNode position) } public override event EventHandler Realized; - protected virtual void OnRealized() + private void OnRealized() { if (Realized != null) Realized(this, EventArgs.Empty); diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Serializers/XmlTypeSerializerCache.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Serializers/XmlTypeSerializerCache.cs index df11f50bad..e736cdce48 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Serializers/XmlTypeSerializerCache.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Serializers/XmlTypeSerializerCache.cs @@ -17,10 +17,8 @@ namespace Castle.Components.DictionaryAdapter.Xml using System; using System.Collections.Generic; using System.ComponentModel; - using System.Reflection; - using System.Xml.Serialization; - internal class XmlTypeSerializerCache : SingletonDispenser + internal sealed class XmlTypeSerializerCache : SingletonDispenser { public static readonly XmlTypeSerializerCache Instance = new XmlTypeSerializerCache(); diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Utilities/XmlSubtreeWriter.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Utilities/XmlSubtreeWriter.cs index 1b44172aa4..2965d56363 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Utilities/XmlSubtreeWriter.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Internal/Utilities/XmlSubtreeWriter.cs @@ -56,7 +56,7 @@ protected override void Dispose(bool managed) } } - private void DisposeWriter(ref XmlWriter writer) + private static void DisposeWriter(ref XmlWriter writer) { var value = Interlocked.Exchange(ref writer, null); if (null != value) value.Close(); diff --git a/src/Castle.Core/Core/Internal/InterfaceAttributeUtil.cs b/src/Castle.Core/Core/Internal/InterfaceAttributeUtil.cs index 8943bf220a..7f64e27577 100644 --- a/src/Castle.Core/Core/Internal/InterfaceAttributeUtil.cs +++ b/src/Castle.Core/Core/Internal/InterfaceAttributeUtil.cs @@ -65,7 +65,7 @@ private InterfaceAttributeUtil(Type derivedType, Type[] baseTypes) results = new List(); } - private Aged[] CollectTypes(Type derivedType, Type[] baseTypes) + private static Aged[] CollectTypes(Type derivedType, Type[] baseTypes) { var ages = new Dictionary(); int age; diff --git a/src/Castle.Core/Core/Internal/InternalsVisible.cs b/src/Castle.Core/Core/Internal/InternalsVisible.cs index d735a6d27e..1e0b2cc75b 100644 --- a/src/Castle.Core/Core/Internal/InternalsVisible.cs +++ b/src/Castle.Core/Core/Internal/InternalsVisible.cs @@ -14,7 +14,7 @@ namespace Castle.Core.Internal { - public class InternalsVisible + public static class InternalsVisible { /// /// Constant to use when making assembly internals visible to Castle.Core diff --git a/src/Castle.Core/Core/Internal/WeakKeyComparer.cs b/src/Castle.Core/Core/Internal/WeakKeyComparer.cs index 369a103cbb..0f1c723576 100644 --- a/src/Castle.Core/Core/Internal/WeakKeyComparer.cs +++ b/src/Castle.Core/Core/Internal/WeakKeyComparer.cs @@ -17,7 +17,7 @@ namespace Castle.Core.Internal using System; using System.Collections.Generic; - internal class WeakKeyComparer : IEqualityComparer + internal sealed class WeakKeyComparer : IEqualityComparer where TKey : class { public static readonly WeakKeyComparer diff --git a/src/Castle.Core/Core/Internal/WeakKeyDictionary.cs b/src/Castle.Core/Core/Internal/WeakKeyDictionary.cs index a96ad10fcc..ff6301aabf 100644 --- a/src/Castle.Core/Core/Internal/WeakKeyDictionary.cs +++ b/src/Castle.Core/Core/Internal/WeakKeyDictionary.cs @@ -18,7 +18,7 @@ namespace Castle.Core.Internal using System.Collections; using System.Collections.Generic; - internal class WeakKeyDictionary : IDictionary + internal sealed class WeakKeyDictionary : IDictionary where TKey : class { private readonly Dictionary dictionary; @@ -177,7 +177,7 @@ public void TrimDeadObjects() dictionary.Remove(key); } - private class KeyCollection : ICollection + private sealed class KeyCollection : ICollection { private readonly ICollection keys; diff --git a/src/Castle.Core/Core/Logging/NullLogger.cs b/src/Castle.Core/Core/Logging/NullLogger.cs index b871dc36e9..8315a74948 100644 --- a/src/Castle.Core/Core/Logging/NullLogger.cs +++ b/src/Castle.Core/Core/Logging/NullLogger.cs @@ -479,7 +479,7 @@ public void WarnFormat(Exception exception, IFormatProvider formatProvider, stri { } - private class NullContextProperties : IContextProperties + private sealed class NullContextProperties : IContextProperties { public static readonly NullContextProperties Instance = new NullContextProperties(); @@ -490,7 +490,7 @@ public object this[string key] } } - private class NullContextStack : IContextStack, IDisposable + private sealed class NullContextStack : IContextStack, IDisposable { public static readonly NullContextStack Instance = new NullContextStack(); @@ -519,7 +519,7 @@ public void Dispose() } } - private class NullContextStacks : IContextStacks + private sealed class NullContextStacks : IContextStacks { public static readonly NullContextStacks Instance = new NullContextStacks(); diff --git a/src/Castle.Core/Core/Logging/TraceLoggerFactory.cs b/src/Castle.Core/Core/Logging/TraceLoggerFactory.cs index 06dfea04ed..093022af05 100644 --- a/src/Castle.Core/Core/Logging/TraceLoggerFactory.cs +++ b/src/Castle.Core/Core/Logging/TraceLoggerFactory.cs @@ -39,7 +39,7 @@ public override ILogger Create(string name) return InternalCreate(name); } - private ILogger InternalCreate(string name) + private static ILogger InternalCreate(string name) { return new TraceLogger(name); } @@ -49,7 +49,7 @@ public override ILogger Create(string name, LoggerLevel level) return InternalCreate(name, level); } - private ILogger InternalCreate(string name, LoggerLevel level) + private static ILogger InternalCreate(string name, LoggerLevel level) { return new TraceLogger(name, level); } diff --git a/src/Castle.Core/Core/ReflectionBasedDictionaryAdapter.cs b/src/Castle.Core/Core/ReflectionBasedDictionaryAdapter.cs index 3080f058a9..97cfc5908e 100644 --- a/src/Castle.Core/Core/ReflectionBasedDictionaryAdapter.cs +++ b/src/Castle.Core/Core/ReflectionBasedDictionaryAdapter.cs @@ -248,7 +248,7 @@ private static bool IsReadable(PropertyInfo property) return property.CanRead && property.GetIndexParameters().Length == 0; } - private class DictionaryEntryEnumeratorAdapter : IDictionaryEnumerator + private sealed class DictionaryEntryEnumeratorAdapter : IDictionaryEnumerator { private readonly IDictionaryEnumerator enumerator; private KeyValuePair current; diff --git a/src/Castle.Core/Core/Resource/AssemblyResource.cs b/src/Castle.Core/Core/Resource/AssemblyResource.cs index 08882f2f34..abc8730872 100644 --- a/src/Castle.Core/Core/Resource/AssemblyResource.cs +++ b/src/Castle.Core/Core/Resource/AssemblyResource.cs @@ -104,7 +104,7 @@ private string GetNameFound(string[] names) string nameFound = null; foreach(string name in names) { - if (string.Compare(resourcePath, name, StringComparison.OrdinalIgnoreCase) == 0) + if (string.Equals(resourcePath, name, StringComparison.OrdinalIgnoreCase)) { nameFound = name; break; @@ -113,14 +113,14 @@ private string GetNameFound(string[] names) return nameFound; } - private string ConvertToResourceName(string assembly, string resource) + private static string ConvertToResourceName(string assembly, string resource) { assembly = GetSimpleName(assembly); // TODO: use path for relative name construction return string.Format(CultureInfo.CurrentCulture, "{0}{1}", assembly, resource.Replace('/', '.')); } - private string GetSimpleName(string assembly) + private static string GetSimpleName(string assembly) { int indexOfComma = assembly.IndexOf(','); if(indexOfComma<0) @@ -130,7 +130,7 @@ private string GetSimpleName(string assembly) return assembly.Substring(0, indexOfComma); } - private string ConvertToPath(string resource) + private static string ConvertToPath(string resource) { string path = resource.Replace('.', '/'); if (path[0] != '/') diff --git a/src/Castle.Core/Core/Resource/CustomUri.cs b/src/Castle.Core/Core/Resource/CustomUri.cs index fe19ab1303..de9b017d4a 100644 --- a/src/Castle.Core/Core/Resource/CustomUri.cs +++ b/src/Castle.Core/Core/Resource/CustomUri.cs @@ -39,7 +39,7 @@ public CustomUri(string resourceIdentifier) { throw new ArgumentNullException(nameof(resourceIdentifier)); } - if (resourceIdentifier == string.Empty) + if (resourceIdentifier.Length == 0) { throw new ArgumentException("Empty resource identifier is not allowed", nameof(resourceIdentifier)); } diff --git a/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs b/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs index 9cedaff87c..8b1f3c6713 100644 --- a/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs +++ b/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs @@ -178,10 +178,10 @@ public IEnumerator GetEnumerator() return ((IEnumerable) dictionary).GetEnumerator(); } - internal class EnumeratorAdapter : IEnumerator> + internal sealed class EnumeratorAdapter : IEnumerator> { private readonly StringObjectDictionaryAdapter adapter; - private IEnumerator keyEnumerator; + private readonly IEnumerator keyEnumerator; private string currentKey; private object currentValue; @@ -220,6 +220,7 @@ KeyValuePair IEnumerator>.Current public void Dispose() { + keyEnumerator.Dispose(); GC.SuppressFinalize(this); } } diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs index fb376b025e..8bca60f22d 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs @@ -16,7 +16,6 @@ namespace Castle.DynamicProxy.Contributors { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -27,7 +26,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tokens; - internal class ClassProxyTargetContributor : CompositeTypeContributor + internal sealed class ClassProxyTargetContributor : CompositeTypeContributor { private readonly Type targetType; @@ -131,7 +130,7 @@ private MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo meth return callBackMethod.MethodBuilder; } - private bool ExplicitlyImplementedInterfaceMethod(MetaMethod method) + private static bool ExplicitlyImplementedInterfaceMethod(MetaMethod method) { return method.MethodOnTarget.IsPrivate; } diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs index e9ab21fc32..98cc4da792 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs @@ -16,16 +16,14 @@ namespace Castle.DynamicProxy.Contributors { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Linq; - using System.Reflection; using Castle.DynamicProxy.Generators; using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using Castle.DynamicProxy.Tokens; - internal class ClassProxyWithTargetTargetContributor : CompositeTypeContributor + internal sealed class ClassProxyWithTargetTargetContributor : CompositeTypeContributor { private readonly Type targetType; @@ -161,7 +159,7 @@ private MethodGenerator IndirectlyCalledMethodGenerator(MetaMethod method, Class contributor); } - private bool IsDirectlyAccessible(MetaMethod method) + private static bool IsDirectlyAccessible(MetaMethod method) { return method.MethodOnTarget.IsPublic; } diff --git a/src/Castle.Core/DynamicProxy/Contributors/FieldReferenceComparer.cs b/src/Castle.Core/DynamicProxy/Contributors/FieldReferenceComparer.cs index 1a658b46f8..7393786617 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/FieldReferenceComparer.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/FieldReferenceComparer.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Contributors using System; using System.Collections.Generic; - internal class FieldReferenceComparer : IComparer + internal sealed class FieldReferenceComparer : IComparer { public int Compare(Type x, Type y) { diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersCollector.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersCollector.cs index ba11dd0370..27ccd9ca00 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersCollector.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersCollector.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators; - internal class InterfaceMembersCollector : MembersCollector + internal sealed class InterfaceMembersCollector : MembersCollector { public InterfaceMembersCollector(Type @interface) : base(@interface) diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs index cce4b3eb01..fc90943f88 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators; - internal class InterfaceMembersOnClassCollector : MembersCollector + internal sealed class InterfaceMembersOnClassCollector : MembersCollector { private readonly InterfaceMapping map; private readonly bool onlyProxyVirtual; diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs index 858a6fb205..02aba6425e 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithOptionalTargetContributor.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators; using Castle.DynamicProxy.Generators.Emitters; - internal class InterfaceProxyWithOptionalTargetContributor : InterfaceProxyWithoutTargetContributor + internal sealed class InterfaceProxyWithOptionalTargetContributor : InterfaceProxyWithoutTargetContributor { private readonly GetTargetReferenceDelegate getTargetReference; diff --git a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithTargetInterfaceTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithTargetInterfaceTargetContributor.cs index b1f4525965..4e97787c2e 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithTargetInterfaceTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithTargetInterfaceTargetContributor.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators; - internal class InterfaceProxyWithTargetInterfaceTargetContributor : InterfaceProxyTargetContributor + internal sealed class InterfaceProxyWithTargetInterfaceTargetContributor : InterfaceProxyTargetContributor { public InterfaceProxyWithTargetInterfaceTargetContributor(Type proxyTargetType, bool allowChangeTarget, INamingScope namingScope) diff --git a/src/Castle.Core/DynamicProxy/Contributors/InvocationWithDelegateContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InvocationWithDelegateContributor.cs index 48f7d29691..7d6b530226 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InvocationWithDelegateContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InvocationWithDelegateContributor.cs @@ -23,7 +23,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using Castle.DynamicProxy.Tokens; - internal class InvocationWithDelegateContributor : IInvocationCreationContributor + internal sealed class InvocationWithDelegateContributor : IInvocationCreationContributor { private readonly Type delegateType; private readonly MetaMethod method; diff --git a/src/Castle.Core/DynamicProxy/Contributors/InvocationWithGenericDelegateContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/InvocationWithGenericDelegateContributor.cs index 3dbeaf5fe7..fdac4fa7cb 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/InvocationWithGenericDelegateContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/InvocationWithGenericDelegateContributor.cs @@ -16,7 +16,6 @@ namespace Castle.DynamicProxy.Contributors { using System; using System.Diagnostics; - using System.Linq; using System.Reflection; using Castle.DynamicProxy.Generators; @@ -25,7 +24,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tokens; - internal class InvocationWithGenericDelegateContributor : IInvocationCreationContributor + internal sealed class InvocationWithGenericDelegateContributor : IInvocationCreationContributor { private readonly Type delegateType; private readonly MetaMethod method; @@ -73,7 +72,7 @@ private Reference GetDelegate(AbstractTypeEmitter invocation, MethodEmitter invo return localReference; } - private AssignStatement SetDelegate(LocalReference localDelegate, Reference localTarget, + private static AssignStatement SetDelegate(LocalReference localDelegate, Reference localTarget, Type closedDelegateType, MethodInfo closedMethodOnTarget) { var delegateCreateDelegate = new MethodInvocationExpression( diff --git a/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs index e6070994ef..13c604c873 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/MixinContributor.cs @@ -17,14 +17,13 @@ namespace Castle.DynamicProxy.Contributors using System; using System.Collections.Generic; using System.Diagnostics; - using System.Reflection; using Castle.DynamicProxy.Generators; using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using Castle.DynamicProxy.Internal; - internal class MixinContributor : CompositeTypeContributor + internal sealed class MixinContributor : CompositeTypeContributor { private readonly bool canChangeTarget; private readonly IList empty = new List(); diff --git a/src/Castle.Core/DynamicProxy/Contributors/WrappedClassMembersCollector.cs b/src/Castle.Core/DynamicProxy/Contributors/WrappedClassMembersCollector.cs index 0b228a9480..3a48f3167c 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/WrappedClassMembersCollector.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/WrappedClassMembersCollector.cs @@ -19,10 +19,9 @@ namespace Castle.DynamicProxy.Contributors using System.Runtime.CompilerServices; using Castle.DynamicProxy.Generators; - using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Internal; - internal class WrappedClassMembersCollector : ClassMembersCollector + internal sealed class WrappedClassMembersCollector : ClassMembersCollector { public WrappedClassMembersCollector(Type type) : base(type) { @@ -49,13 +48,13 @@ protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGener return new MetaMethod(method, method, isStandalone, accepted, hasTarget: true); } - protected bool IsGeneratedByTheCompiler(FieldInfo field) + private static bool IsGeneratedByTheCompiler(FieldInfo field) { // for example fields backing autoproperties return field.IsDefined(typeof(CompilerGeneratedAttribute)); } - protected virtual bool IsOKToBeOnProxy(FieldInfo field) + private static bool IsOKToBeOnProxy(FieldInfo field) { return IsGeneratedByTheCompiler(field); } diff --git a/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs b/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs index 68ac6c765e..62b4ca3b53 100644 --- a/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs +++ b/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs @@ -34,9 +34,9 @@ namespace Castle.DynamicProxy public class CustomAttributeInfo : IEquatable { // Cached empty arrays to avoid unnecessary allocations - private static readonly PropertyInfo[] EmptyProperties = new PropertyInfo[0]; - private static readonly FieldInfo[] EmptyFields = new FieldInfo[0]; - private static readonly object?[] EmptyValues = new object?[0]; + private static readonly PropertyInfo[] EmptyProperties = Array.Empty(); + private static readonly FieldInfo[] EmptyFields = Array.Empty(); + private static readonly object?[] EmptyValues = Array.Empty(); private static readonly AttributeArgumentValueEqualityComparer ValueComparer = new AttributeArgumentValueEqualityComparer(); @@ -295,7 +295,7 @@ private static int CombineMemberHashCodes(IDictionary dict) } } - private IDictionary MakeNameValueDictionary(T[] members, object?[] values) + private static IDictionary MakeNameValueDictionary(T[] members, object?[] values) where T : MemberInfo { var dict = new Dictionary(); @@ -306,7 +306,7 @@ private static int CombineMemberHashCodes(IDictionary dict) return dict; } - private class AttributeArgumentValueEqualityComparer : IEqualityComparer + private sealed class AttributeArgumentValueEqualityComparer : IEqualityComparer { new public bool Equals(object? x, object? y) { diff --git a/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs b/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs index 703e4aafb5..82394caf05 100644 --- a/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs +++ b/src/Castle.Core/DynamicProxy/DefaultProxyBuilder.cs @@ -117,7 +117,7 @@ public Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[]? return generator.GetProxyType(); } - private void AssertValidMixins(ProxyGenerationOptions options, string paramName) + private static void AssertValidMixins(ProxyGenerationOptions options, string paramName) { try { @@ -129,12 +129,12 @@ private void AssertValidMixins(ProxyGenerationOptions options, string paramName) } } - private void AssertValidType(Type target, string paramName) + private static void AssertValidType(Type target, string paramName) { AssertValidTypeForTarget(target, target, paramName); } - private void AssertValidTypeForTarget(Type type, Type target, string paramName) + private static void AssertValidTypeForTarget(Type type, Type target, string paramName) { if (type.IsGenericTypeDefinition) { @@ -152,7 +152,7 @@ private void AssertValidTypeForTarget(Type type, Type target, string paramName) } } - private void AssertValidTypes(IEnumerable? targetTypes, string paramName) + private static void AssertValidTypes(IEnumerable? targetTypes, string paramName) { if (targetTypes != null) { diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs index 02f6012380..2fd7a1bebd 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseClassProxyGenerator.cs @@ -203,7 +203,7 @@ private IEnumerable GetTypeImplementerMapping(out IEnumerable mapping) + protected static void AddMapping(Type @interface, ITypeContributor implementer, IDictionary mapping) { Debug.Assert(implementer != null, "implementer != null"); Debug.Assert(@interface != null, "@interface != null"); @@ -120,7 +120,7 @@ protected void AddMappingForISerializable(IDictionary ty /// /// It is safe to add mapping (no mapping for the interface exists) /// - protected void AddMappingNoCheck(Type @interface, ITypeContributor implementer, + protected static void AddMappingNoCheck(Type @interface, ITypeContributor implementer, IDictionary mapping) { mapping.Add(@interface, implementer); @@ -134,7 +134,7 @@ protected virtual ClassEmitter BuildClassEmitter(string typeName, Type parentTyp return new ClassEmitter(Scope, typeName, parentType, interfaces); } - protected void CheckNotGenericTypeDefinition(Type type, string argumentName) + protected static void CheckNotGenericTypeDefinition(Type type, string argumentName) { if (type != null && type.IsGenericTypeDefinition) { @@ -142,7 +142,7 @@ protected void CheckNotGenericTypeDefinition(Type type, string argumentName) } } - protected void CheckNotGenericTypeDefinitions(IEnumerable types, string argumentName) + protected static void CheckNotGenericTypeDefinitions(IEnumerable types, string argumentName) { if (types == null) { @@ -154,7 +154,7 @@ protected void CheckNotGenericTypeDefinitions(IEnumerable types, string ar } } - protected void CompleteInitCacheMethod(CodeBuilder constCodeBuilder) + protected static void CompleteInitCacheMethod(CodeBuilder constCodeBuilder) { constCodeBuilder.AddStatement(new ReturnStatement()); } @@ -166,7 +166,7 @@ protected virtual void CreateFields(ClassEmitter emitter) CreateInterceptorsField(emitter); } - protected void CreateInterceptorsField(ClassEmitter emitter) + protected static void CreateInterceptorsField(ClassEmitter emitter) { var interceptorsField = emitter.CreateField("__interceptors", typeof(IInterceptor[])); @@ -175,7 +175,7 @@ protected void CreateInterceptorsField(ClassEmitter emitter) #endif } - protected FieldReference CreateOptionsField(ClassEmitter emitter) + protected static FieldReference CreateOptionsField(ClassEmitter emitter) { return emitter.CreateStaticField("proxyGenerationOptions", typeof(ProxyGenerationOptions)); } @@ -214,7 +214,7 @@ protected void EnsureOptionsOverrideEqualsAndGetHashCode() } } - protected void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseConstructor, + protected static void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseConstructor, params FieldReference[] fields) { ArgumentReference[] args; @@ -284,7 +284,7 @@ protected void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseCon constructor.CodeBuilder.AddStatement(new ReturnStatement()); } - protected void GenerateConstructors(ClassEmitter emitter, Type baseType, params FieldReference[] fields) + protected static void GenerateConstructors(ClassEmitter emitter, Type baseType, params FieldReference[] fields) { var constructors = baseType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); @@ -307,7 +307,7 @@ protected void GenerateConstructors(ClassEmitter emitter, Type baseType, params /// This constructor is important to allow proxies to be XML serializable /// /// - protected void GenerateParameterlessConstructor(ClassEmitter emitter, Type baseClass, FieldReference interceptorField) + protected static void GenerateParameterlessConstructor(ClassEmitter emitter, Type baseClass, FieldReference interceptorField) { // Check if the type actually has a default constructor var defaultConstructor = baseClass.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, @@ -340,7 +340,7 @@ protected void GenerateParameterlessConstructor(ClassEmitter emitter, Type baseC constructor.CodeBuilder.AddStatement(new ReturnStatement()); } - protected ConstructorEmitter GenerateStaticConstructor(ClassEmitter emitter) + protected static ConstructorEmitter GenerateStaticConstructor(ClassEmitter emitter) { return emitter.CreateTypeConstructor(); } @@ -389,7 +389,7 @@ protected void InitializeStaticFields(Type builtType) builtType.SetStaticField("proxyGenerationOptions", BindingFlags.NonPublic, ProxyGenerationOptions); } - private bool OverridesEqualsAndGetHashCode(Type type) + private static bool OverridesEqualsAndGetHashCode(Type type) { var equalsMethod = type.GetMethod("Equals", BindingFlags.Public | BindingFlags.Instance); if (equalsMethod == null || equalsMethod.DeclaringType == typeof(object) || equalsMethod.IsAbstract) diff --git a/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs b/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs index d0a98b8f62..13df32e3cb 100644 --- a/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs +++ b/src/Castle.Core/DynamicProxy/Generators/CacheKey.cs @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators #if FEATURE_SERIALIZATION [Serializable] #endif - internal class CacheKey + internal sealed class CacheKey { private readonly MemberInfo target; private readonly Type[] interfaces; diff --git a/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs index 7222725f31..90162f7b59 100644 --- a/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.cs @@ -23,7 +23,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tokens; - internal class CompositionInvocationTypeGenerator : InvocationTypeGenerator + internal sealed class CompositionInvocationTypeGenerator : InvocationTypeGenerator { public static readonly Type BaseType = typeof(CompositionInvocation); diff --git a/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs index 8efd6d40cf..18cd03eabd 100644 --- a/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/DelegateTypeGenerator.cs @@ -19,9 +19,8 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - using Castle.DynamicProxy.Internal; - internal class DelegateTypeGenerator : IGenerator + internal sealed class DelegateTypeGenerator : IGenerator { private const TypeAttributes DelegateFlags = TypeAttributes.Class | TypeAttributes.Public | @@ -46,7 +45,7 @@ public AbstractTypeEmitter Generate(ClassEmitter @class, INamingScope namingScop return emitter; } - private void BuildConstructor(AbstractTypeEmitter emitter) + private static void BuildConstructor(AbstractTypeEmitter emitter) { var constructor = emitter.CreateConstructor(new ArgumentReference(typeof(object)), new ArgumentReference(typeof(IntPtr))); diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs index 361a6bdf8e..732502a34b 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/AbstractTypeEmitter.cs @@ -337,7 +337,7 @@ public void SetGenericTypeParameters(GenericTypeParameterBuilder[] genericTypePa genericTypeParams = genericTypeParameterBuilders; } - protected Type CreateType(TypeBuilder type) + protected static Type CreateType(TypeBuilder type) { return type.CreateTypeInfo(); } diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/ClassEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/ClassEmitter.cs index 07a658aee4..cdff735f02 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/ClassEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/ClassEmitter.cs @@ -22,7 +22,7 @@ namespace Castle.DynamicProxy.Generators.Emitters using Castle.DynamicProxy.Internal; - internal class ClassEmitter : AbstractTypeEmitter + internal sealed class ClassEmitter : AbstractTypeEmitter { internal const TypeAttributes DefaultAttributes = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable; @@ -75,7 +75,7 @@ internal bool InStrongNamedModule get { return StrongNameUtil.IsAssemblySigned(TypeBuilder.Assembly); } } - protected virtual IEnumerable InitializeGenericArgumentsFromBases(ref Type baseType, + private static IEnumerable InitializeGenericArgumentsFromBases(ref Type baseType, IEnumerable interfaces) { if (baseType != null && baseType.IsGenericTypeDefinition) diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/EventEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/EventEmitter.cs index 08ad72ea3e..dbc7588f3d 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/EventEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/EventEmitter.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters using System.Reflection; using System.Reflection.Emit; - internal class EventEmitter : IMemberEmitter + internal sealed class EventEmitter : IMemberEmitter { private readonly EventBuilder eventBuilder; private readonly Type type; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/GenericUtil.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/GenericUtil.cs index 458ce775a8..553817d246 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/GenericUtil.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/GenericUtil.cs @@ -19,12 +19,11 @@ namespace Castle.DynamicProxy.Generators.Emitters using System.Reflection; using System.Reflection.Emit; - using Castle.Core.Internal; using Castle.DynamicProxy.Internal; internal delegate GenericTypeParameterBuilder[] ApplyGenArgs(string[] argumentNames); - internal class GenericUtil + internal sealed class GenericUtil { public static GenericTypeParameterBuilder[] CopyGenericArguments( MethodInfo methodToCopyGenericsFrom, diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs index 7d2579f10f..c26aea7a37 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/MethodEmitter.cs @@ -15,10 +15,8 @@ namespace Castle.DynamicProxy.Generators.Emitters { using System; - using System.Collections.Generic; using System.Diagnostics; using System.Globalization; - using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -26,7 +24,7 @@ namespace Castle.DynamicProxy.Generators.Emitters using Castle.DynamicProxy.Internal; [DebuggerDisplay("{builder.Name}")] - internal class MethodEmitter : IMemberEmitter + internal sealed class MethodEmitter : IMemberEmitter { private readonly MethodBuilder builder; private readonly CodeBuilder codeBuilder; @@ -34,7 +32,7 @@ internal class MethodEmitter : IMemberEmitter private ArgumentReference[] arguments; - protected internal MethodEmitter(MethodBuilder builder) + private MethodEmitter(MethodBuilder builder) { this.builder = builder; codeBuilder = new CodeBuilder(); @@ -124,7 +122,7 @@ public void SetParameters(Type[] paramTypes) ArgumentsUtil.InitializeArgumentsByPosition(arguments, MethodBuilder.IsStatic); } - public virtual void EnsureValidCodeBlock() + public void EnsureValidCodeBlock() { if (ImplementedByRuntime == false && CodeBuilder.IsEmpty) { @@ -139,7 +137,7 @@ public virtual void EnsureValidCodeBlock() } } - public virtual void Generate() + public void Generate() { if (ImplementedByRuntime) { @@ -186,7 +184,7 @@ private void DefineParameters(ParameterInfo[] parameters) } } - private void CopyDefaultValueConstant(ParameterInfo from, ParameterBuilder to) + private static void CopyDefaultValueConstant(ParameterInfo from, ParameterBuilder to) { Debug.Assert(from != null); Debug.Assert(to != null); diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/NestedClassEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/NestedClassEmitter.cs index d019a7bfde..0807280d9f 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/NestedClassEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/NestedClassEmitter.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters using System.Reflection; using System.Reflection.Emit; - internal class NestedClassEmitter : AbstractTypeEmitter + internal sealed class NestedClassEmitter : AbstractTypeEmitter { public NestedClassEmitter(AbstractTypeEmitter mainType, string name, Type baseType, Type[] interfaces) : this( diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/PropertyEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/PropertyEmitter.cs index c2674b3dea..1034e64e98 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/PropertyEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/PropertyEmitter.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters using System.Reflection; using System.Reflection.Emit; - internal class PropertyEmitter : IMemberEmitter + internal sealed class PropertyEmitter : IMemberEmitter { private readonly PropertyBuilder builder; private readonly AbstractTypeEmitter parentTypeEmitter; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ArgumentReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ArgumentReference.cs index 19be72db47..55aeb84cc0 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ArgumentReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ArgumentReference.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection.Emit; [DebuggerDisplay("argument {Type}")] - internal class ArgumentReference : TypeReference + internal sealed class ArgumentReference : TypeReference { public ArgumentReference(Type argumentType) : base(argumentType) diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs index 6f0ce6c0ca..cfae6c5709 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection.Emit; [DebuggerDisplay("{reference} as {type}")] - internal class AsTypeReference : Reference + internal sealed class AsTypeReference : Reference { private readonly Reference reference; private readonly Type type; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs index 5c4b2a70f8..c67e4aa075 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class AssignArgumentStatement : IStatement + internal sealed class AssignArgumentStatement : IStatement { private readonly ArgumentReference argument; private readonly IExpression expression; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs index b8ea4d599f..5c9af2baca 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArrayStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class AssignArrayStatement : IStatement + internal sealed class AssignArrayStatement : IStatement { private readonly Reference targetArray; private readonly int targetPosition; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignStatement.cs index 4d33b78ac9..0170b14ad2 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class AssignStatement : IStatement + internal sealed class AssignStatement : IStatement { private readonly IExpression expression; private readonly Reference target; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BlockStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BlockStatement.cs index c3526eddf6..9875e0bb78 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BlockStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/BlockStatement.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Collections.Generic; using System.Reflection.Emit; - internal class BlockStatement : IStatement + internal sealed class BlockStatement : IStatement { private readonly List statements = new List(); diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ByRefReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ByRefReference.cs index f6fc69ad5b..9bec9d8d4d 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ByRefReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ByRefReference.cs @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST [DebuggerDisplay("&{localReference}")] - internal class ByRefReference : TypeReference + internal sealed class ByRefReference : TypeReference { private readonly LocalReference localReference; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConstructorInvocationStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConstructorInvocationStatement.cs index be9cfe62e4..8e3e72d7ed 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConstructorInvocationStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConstructorInvocationStatement.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection; using System.Reflection.Emit; - internal class ConstructorInvocationStatement : IStatement + internal sealed class ConstructorInvocationStatement : IStatement { private readonly IExpression[] args; private readonly ConstructorInfo cmethod; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConvertExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConvertExpression.cs index 5e90d3930e..4738c691fa 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConvertExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ConvertExpression.cs @@ -15,10 +15,9 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System; - using System.Reflection; using System.Reflection.Emit; - internal class ConvertExpression : IExpression + internal sealed class ConvertExpression : IExpression { private readonly IExpression right; private Type fromType; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs index c4668cf208..bfa416e3b3 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs @@ -15,10 +15,9 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System; - using System.Reflection; using System.Reflection.Emit; - internal class DefaultValueExpression : IExpression + internal sealed class DefaultValueExpression : IExpression { private readonly Type type; @@ -70,7 +69,7 @@ private void EmitByRef(ILGenerator gen) } } - private bool IsPrimitiveOrClass(Type type) + private static bool IsPrimitiveOrClass(Type type) { if (type.IsPrimitive && type != typeof(IntPtr) && type != typeof(UIntPtr)) { diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/EndExceptionBlockStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/EndExceptionBlockStatement.cs index f8b9339c83..469ec7ad93 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/EndExceptionBlockStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/EndExceptionBlockStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class EndExceptionBlockStatement : IStatement + internal sealed class EndExceptionBlockStatement : IStatement { public void Emit(ILGenerator gen) { diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FieldReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FieldReference.cs index 837a02bdfc..5fb04723fa 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FieldReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FieldReference.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection.Emit; [DebuggerDisplay("{fieldBuilder.Name} ({fieldBuilder.FieldType})")] - internal class FieldReference : Reference + internal sealed class FieldReference : Reference { private readonly FieldInfo field; private readonly FieldBuilder fieldBuilder; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FinallyStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FinallyStatement.cs index ff2ba63aa5..9500b82f31 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FinallyStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FinallyStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class FinallyStatement : IStatement + internal sealed class FinallyStatement : IStatement { public void Emit(ILGenerator gen) { diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IfNullExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IfNullExpression.cs index 333a732ac2..07f879384b 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IfNullExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IfNullExpression.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System; using System.Reflection.Emit; - internal class IfNullExpression : IExpression, IStatement + internal sealed class IfNullExpression : IExpression, IStatement { private readonly IExpressionOrStatement ifNotNull; private readonly IExpressionOrStatement ifNull; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IndirectReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IndirectReference.cs index 321d43954d..d60b0459b4 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IndirectReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/IndirectReference.cs @@ -16,7 +16,6 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System; using System.Diagnostics; - using System.Reflection; using System.Reflection.Emit; /// @@ -24,7 +23,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST /// ByRef and provides indirect load/store support. /// [DebuggerDisplay("&{OwnerReference}")] - internal class IndirectReference : TypeReference + internal sealed class IndirectReference : TypeReference { public IndirectReference(TypeReference byRefReference) : base(byRefReference, byRefReference.Type.GetElementType()) diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralBoolExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralBoolExpression.cs index 2fb5050115..8c59d9e806 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralBoolExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralBoolExpression.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class LiteralBoolExpression : IExpression + internal sealed class LiteralBoolExpression : IExpression { private readonly bool value; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralIntExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralIntExpression.cs index 3e07dd435c..93307eabe7 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralIntExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralIntExpression.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class LiteralIntExpression : IExpression + internal sealed class LiteralIntExpression : IExpression { private readonly int value; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralStringExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralStringExpression.cs index f8a842d1a6..6d0557b599 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralStringExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LiteralStringExpression.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class LiteralStringExpression : IExpression + internal sealed class LiteralStringExpression : IExpression { private readonly string value; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadRefArrayElementExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadRefArrayElementExpression.cs index 311a46c432..fffbad0e44 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadRefArrayElementExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LoadRefArrayElementExpression.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class LoadRefArrayElementExpression : IExpression + internal sealed class LoadRefArrayElementExpression : IExpression { private readonly Reference arrayReference; private readonly LiteralIntExpression index; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LocalReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LocalReference.cs index 768bac77f3..8eacad04ce 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LocalReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/LocalReference.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection.Emit; [DebuggerDisplay("local {Type}")] - internal class LocalReference : TypeReference + internal sealed class LocalReference : TypeReference { private LocalBuilder localBuilder; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodInvocationExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodInvocationExpression.cs index 4261758eea..2977896955 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodInvocationExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodInvocationExpression.cs @@ -17,11 +17,11 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection; using System.Reflection.Emit; - internal class MethodInvocationExpression : IExpression, IStatement + internal sealed class MethodInvocationExpression : IExpression, IStatement { - protected readonly IExpression[] args; - protected readonly MethodInfo method; - protected readonly Reference owner; + private readonly IExpression[] args; + private readonly MethodInfo method; + private readonly Reference owner; public MethodInvocationExpression(MethodInfo method, params IExpression[] args) : this(SelfReference.Self, method, args) diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodTokenExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodTokenExpression.cs index cc70b095a2..4531f74f47 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodTokenExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodTokenExpression.cs @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using Castle.DynamicProxy.Tokens; - internal class MethodTokenExpression : IExpression + internal sealed class MethodTokenExpression : IExpression { private readonly MethodInfo method; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs index e6a2524c9f..559e994bb9 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewArrayExpression.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System; using System.Reflection.Emit; - internal class NewArrayExpression : IExpression + internal sealed class NewArrayExpression : IExpression { private readonly Type arrayType; private readonly int size; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs index d5abeff471..78a981406e 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NewInstanceExpression.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection; using System.Reflection.Emit; - internal class NewInstanceExpression : IExpression + internal sealed class NewInstanceExpression : IExpression { private readonly IExpression[] arguments; private ConstructorInfo constructor; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullCoalescingOperatorExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullCoalescingOperatorExpression.cs index 7c492a6ae8..e4ae464756 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullCoalescingOperatorExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullCoalescingOperatorExpression.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System; using System.Reflection.Emit; - internal class NullCoalescingOperatorExpression : IExpression + internal sealed class NullCoalescingOperatorExpression : IExpression { private readonly IExpression @default; private readonly IExpression expression; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullExpression.cs index cdf04957c5..260fea5097 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/NullExpression.cs @@ -16,11 +16,11 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class NullExpression : IExpression + internal sealed class NullExpression : IExpression { public static readonly NullExpression Instance = new NullExpression(); - protected NullExpression() + private NullExpression() { } diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReferencesToObjectArrayExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReferencesToObjectArrayExpression.cs index dea87ef9c7..12b7ba5663 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReferencesToObjectArrayExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReferencesToObjectArrayExpression.cs @@ -15,10 +15,9 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System; - using System.Reflection; using System.Reflection.Emit; - internal class ReferencesToObjectArrayExpression : IExpression + internal sealed class ReferencesToObjectArrayExpression : IExpression { private readonly TypeReference[] args; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReturnStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReturnStatement.cs index 35bd01daf2..618c70aa76 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReturnStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ReturnStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class ReturnStatement : IStatement + internal sealed class ReturnStatement : IStatement { private readonly IExpression expression; private readonly Reference reference; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/SelfReference.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/SelfReference.cs index 085d964da1..59eb3fd722 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/SelfReference.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/SelfReference.cs @@ -19,11 +19,11 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using System.Reflection.Emit; [DebuggerDisplay("this")] - internal class SelfReference : Reference + internal sealed class SelfReference : Reference { public static readonly SelfReference Self = new SelfReference(); - protected SelfReference() : base(null) + private SelfReference() : base(null) { } diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ThrowStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ThrowStatement.cs index f34a3c563d..da1bf5ba57 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ThrowStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ThrowStatement.cs @@ -15,10 +15,9 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System; - using System.Reflection; using System.Reflection.Emit; - internal class ThrowStatement : IStatement + internal sealed class ThrowStatement : IStatement { private readonly string errorMessage; private readonly Type exceptionType; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TryStatement.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TryStatement.cs index 69eb9bd48e..42db9b6e42 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TryStatement.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TryStatement.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST { using System.Reflection.Emit; - internal class TryStatement : IStatement + internal sealed class TryStatement : IStatement { public void Emit(ILGenerator gen) { diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TypeTokenExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TypeTokenExpression.cs index 2a390c286c..165572b3a6 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TypeTokenExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/TypeTokenExpression.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST using Castle.DynamicProxy.Tokens; - internal class TypeTokenExpression : IExpression + internal sealed class TypeTokenExpression : IExpression { private readonly Type type; diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/TypeConstructorEmitter.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/TypeConstructorEmitter.cs index 2167a63a35..d4578fc387 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/TypeConstructorEmitter.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/TypeConstructorEmitter.cs @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters { using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - internal class TypeConstructorEmitter : ConstructorEmitter + internal sealed class TypeConstructorEmitter : ConstructorEmitter { internal TypeConstructorEmitter(AbstractTypeEmitter mainType) : base(mainType, mainType.TypeBuilder.DefineTypeInitializer()) diff --git a/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs index 6b7364f6e5..56c39a67aa 100644 --- a/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/ForwardingMethodGenerator.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - internal class ForwardingMethodGenerator : MethodGenerator + internal sealed class ForwardingMethodGenerator : MethodGenerator { private readonly GetTargetReferenceDelegate getTargetReference; diff --git a/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs index b02d5876e9..e734a79503 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InheritanceInvocationTypeGenerator.cs @@ -22,7 +22,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tokens; - internal class InheritanceInvocationTypeGenerator : InvocationTypeGenerator + internal sealed class InheritanceInvocationTypeGenerator : InvocationTypeGenerator { public static readonly Type BaseType = typeof(InheritanceInvocation); diff --git a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs index dc4ac91c41..d5d256e1ca 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs @@ -60,7 +60,7 @@ protected override void AddMappingForAdditionalInterfaces(CompositeTypeContribut } } - private bool ImplementedByTarget(ICollection targetInterfaces, Type @interface) + private static bool ImplementedByTarget(ICollection targetInterfaces, Type @interface) { return targetInterfaces.Contains(@interface); } diff --git a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs index c4e022de3a..b2d826e7dc 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs @@ -57,7 +57,7 @@ public AbstractTypeEmitter Generate(ClassEmitter @class, INamingScope namingScop { var methodInfo = method.Method; - var interfaces = new Type[0]; + var interfaces = Type.EmptyTypes; if (canChangeTarget) { @@ -182,7 +182,7 @@ protected virtual void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocat invokeMethodOnTarget.CodeBuilder.AddStatement(new ReturnStatement()); } - private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictionary byRefArguments) + private static void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictionary byRefArguments) { if (byRefArguments.Count == 0) { @@ -226,7 +226,7 @@ private ConstructorEmitter CreateConstructor(AbstractTypeEmitter invocation, Arg return contributor.CreateConstructor(baseCtorArguments, invocation); } - private void EmitCallThrowOnNoTarget(MethodEmitter invokeMethodOnTarget) + private static void EmitCallThrowOnNoTarget(MethodEmitter invokeMethodOnTarget) { var throwOnNoTarget = new MethodInvocationExpression(InvocationMethods.ThrowOnNoTarget); diff --git a/src/Castle.Core/DynamicProxy/Generators/MetaEvent.cs b/src/Castle.Core/DynamicProxy/Generators/MetaEvent.cs index a326d4fc73..e203fa407a 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MetaEvent.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MetaEvent.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; - internal class MetaEvent : MetaTypeElement, IEquatable + internal sealed class MetaEvent : MetaTypeElement, IEquatable { private readonly MetaMethod adder; private readonly MetaMethod remover; diff --git a/src/Castle.Core/DynamicProxy/Generators/MetaMethod.cs b/src/Castle.Core/DynamicProxy/Generators/MetaMethod.cs index 91b66bf393..a286ba8f0b 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MetaMethod.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MetaMethod.cs @@ -19,7 +19,7 @@ namespace Castle.DynamicProxy.Generators using System.Reflection; [DebuggerDisplay("{Method}")] - internal class MetaMethod : MetaTypeElement, IEquatable + internal sealed class MetaMethod : MetaTypeElement, IEquatable { private const MethodAttributes ExplicitImplementationAttributes = MethodAttributes.Virtual | MethodAttributes.Public | diff --git a/src/Castle.Core/DynamicProxy/Generators/MetaProperty.cs b/src/Castle.Core/DynamicProxy/Generators/MetaProperty.cs index b2b66066c6..2750c4a34a 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MetaProperty.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MetaProperty.cs @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; - internal class MetaProperty : MetaTypeElement, IEquatable + internal sealed class MetaProperty : MetaTypeElement, IEquatable { private readonly Type[] arguments; private readonly PropertyAttributes attributes; diff --git a/src/Castle.Core/DynamicProxy/Generators/MetaType.cs b/src/Castle.Core/DynamicProxy/Generators/MetaType.cs index cd8e04ef49..d90bf2b04c 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MetaType.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MetaType.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators using System.Collections.Generic; using System.Reflection; - internal class MetaType + internal sealed class MetaType { private readonly MetaTypeElementCollection events = new MetaTypeElementCollection(); private readonly MetaTypeElementCollection methods = new MetaTypeElementCollection(); diff --git a/src/Castle.Core/DynamicProxy/Generators/MetaTypeElementCollection.cs b/src/Castle.Core/DynamicProxy/Generators/MetaTypeElementCollection.cs index 210b2f1f15..2e5a77fa8a 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MetaTypeElementCollection.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MetaTypeElementCollection.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators using System.Collections; using System.Collections.Generic; - internal class MetaTypeElementCollection : IEnumerable + internal sealed class MetaTypeElementCollection : IEnumerable where TElement : MetaTypeElement, IEquatable { private readonly ICollection items = new List(); diff --git a/src/Castle.Core/DynamicProxy/Generators/MethodSignatureComparer.cs b/src/Castle.Core/DynamicProxy/Generators/MethodSignatureComparer.cs index eae924c178..a952c20e44 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MethodSignatureComparer.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MethodSignatureComparer.cs @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators using System.Collections.Generic; using System.Reflection; - internal class MethodSignatureComparer : IEqualityComparer + internal sealed class MethodSignatureComparer : IEqualityComparer { public static readonly MethodSignatureComparer Instance = new MethodSignatureComparer(); @@ -101,7 +101,7 @@ public bool EqualReturnTypes(MethodInfo x, MethodInfo y) return false; } - private bool EqualSignatureTypes(Type x, Type y) + private static bool EqualSignatureTypes(Type x, Type y) { if (x.IsByRef != y.IsByRef) { @@ -186,7 +186,7 @@ public int GetHashCode(MethodInfo obj) return obj.Name.GetHashCode() ^ obj.GetParameters().Length; // everything else would be too cumbersome } - private bool EqualNames(MethodInfo x, MethodInfo y) + private static bool EqualNames(MethodInfo x, MethodInfo y) { return x.Name == y.Name; } diff --git a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs index ccf636a39e..034e0868bd 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.cs @@ -15,21 +15,19 @@ namespace Castle.DynamicProxy.Generators { using System; - using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; #if FEATURE_SERIALIZATION using System.Xml.Serialization; #endif - using Castle.Core.Internal; using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using Castle.DynamicProxy.Internal; using Castle.DynamicProxy.Tokens; - internal class MethodWithInvocationGenerator : MethodGenerator + internal sealed class MethodWithInvocationGenerator : MethodGenerator { private readonly IInvocationCreationContributor contributor; private readonly GetTargetExpressionDelegate getTargetExpression; @@ -57,7 +55,7 @@ public MethodWithInvocationGenerator(MetaMethod method, IExpression interceptors this.contributor = contributor; } - protected FieldReference BuildMethodInterceptorsField(ClassEmitter @class, MethodInfo method, INamingScope namingScope) + private static FieldReference BuildMethodInterceptorsField(ClassEmitter @class, MethodInfo method, INamingScope namingScope) { var methodInterceptors = @class.CreateField( namingScope.GetUniqueName(string.Format("interceptors_{0}", method.Name)), @@ -195,7 +193,7 @@ private IExpression SetMethodInterceptors(ClassEmitter @class, INamingScope nami return methodInterceptorsField; } - private void EmitLoadGenericMethodArguments(MethodEmitter methodEmitter, MethodInfo method, Reference invocationLocal) + private static void EmitLoadGenericMethodArguments(MethodEmitter methodEmitter, MethodInfo method, Reference invocationLocal) { var genericParameters = Array.FindAll(method.GetGenericArguments(), t => t.IsGenericParameter); var genericParamsArrayLocal = methodEmitter.CodeBuilder.DeclareLocal(typeof(Type[])); @@ -235,7 +233,7 @@ private IExpression[] ModifyArguments(ClassEmitter @class, IExpression[] argumen return contributor.GetConstructorInvocationArguments(arguments, @class); } - private bool HasByRefArguments(ArgumentReference[] arguments) + private static bool HasByRefArguments(ArgumentReference[] arguments) { for (int i = 0; i < arguments.Length; i++ ) { diff --git a/src/Castle.Core/DynamicProxy/Generators/MinimalisticMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/MinimalisticMethodGenerator.cs index 965ea8e78e..6cec1ac488 100644 --- a/src/Castle.Core/DynamicProxy/Generators/MinimalisticMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/MinimalisticMethodGenerator.cs @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - internal class MinimalisticMethodGenerator : MethodGenerator + internal sealed class MinimalisticMethodGenerator : MethodGenerator { public MinimalisticMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod) : base(method, overrideMethod) @@ -44,7 +44,7 @@ protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, C return emitter; } - private void InitOutParameters(MethodEmitter emitter, ParameterInfo[] parameters) + private static void InitOutParameters(MethodEmitter emitter, ParameterInfo[] parameters) { for (var index = 0; index < parameters.Length; index++) { diff --git a/src/Castle.Core/DynamicProxy/Generators/NamingScope.cs b/src/Castle.Core/DynamicProxy/Generators/NamingScope.cs index 57958b23ab..adc1fccc2a 100644 --- a/src/Castle.Core/DynamicProxy/Generators/NamingScope.cs +++ b/src/Castle.Core/DynamicProxy/Generators/NamingScope.cs @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Generators using System.Collections.Generic; using System.Diagnostics; - internal class NamingScope : INamingScope + internal sealed class NamingScope : INamingScope { private readonly IDictionary names = new Dictionary(); private readonly INamingScope parentScope; diff --git a/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs index 51a36f2f73..858abe476d 100644 --- a/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Generators using Castle.DynamicProxy.Generators.Emitters; using Castle.DynamicProxy.Generators.Emitters.SimpleAST; - internal class OptionallyForwardingMethodGenerator : MethodGenerator + internal sealed class OptionallyForwardingMethodGenerator : MethodGenerator { // TODO: This class largely duplicates code from Forwarding and Minimalistic generators. Should be refactored to change that private readonly GetTargetReferenceDelegate getTargetReference; @@ -76,7 +76,7 @@ private IStatement IfNull(Type returnType) return statements; } - private void InitOutParameters(BlockStatement statements, ParameterInfo[] parameters) + private static void InitOutParameters(BlockStatement statements, ParameterInfo[] parameters) { for (var index = 0; index < parameters.Length; index++) { diff --git a/src/Castle.Core/DynamicProxy/Internal/AttributeUtil.cs b/src/Castle.Core/DynamicProxy/Internal/AttributeUtil.cs index ee7e129cb0..a31c6b81ad 100644 --- a/src/Castle.Core/DynamicProxy/Internal/AttributeUtil.cs +++ b/src/Castle.Core/DynamicProxy/Internal/AttributeUtil.cs @@ -205,7 +205,7 @@ private static bool ShouldSkipAttributeReplication(Type attribute, bool ignoreIn var constructor = typeof(TAttribute).GetConstructor(Type.EmptyTypes); Debug.Assert(constructor != null, "constructor != null"); - return new CustomAttributeInfo(constructor, new object[0]); + return new CustomAttributeInfo(constructor, Array.Empty()); } public static CustomAttributeInfo CreateInfo(Type attribute, object[] constructorArguments) diff --git a/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs b/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs index 2dbe74aaba..2574203c93 100644 --- a/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs +++ b/src/Castle.Core/DynamicProxy/ProxyGenerationOptions.cs @@ -238,7 +238,7 @@ public object[] MixinsAsArray() { if (mixins == null) { - return new object[0]; + return Array.Empty(); } return mixins.ToArray(); diff --git a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs index 2074dce620..1d4deaf393 100644 --- a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs @@ -321,7 +321,7 @@ public virtual object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type return Activator.CreateInstance(generatedType, arguments.ToArray())!; } - protected List GetConstructorArguments(object? target, IInterceptor[] interceptors, + protected static List GetConstructorArguments(object? target, IInterceptor[] interceptors, ProxyGenerationOptions options) { // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments) @@ -858,7 +858,7 @@ public TClass CreateClassProxyWithTarget(TClass? target, params IInterce Type.EmptyTypes, target, ProxyGenerationOptions.Default, - new object[0], + Array.Empty(), interceptors); } @@ -888,7 +888,7 @@ public TClass CreateClassProxyWithTarget(TClass? target, ProxyGeneration Type.EmptyTypes, target, options, - new object[0], + Array.Empty(), interceptors); } @@ -921,7 +921,7 @@ public object CreateClassProxyWithTarget(Type classToProxy, Type[]? additionalIn additionalInterfacesToProxy, target, ProxyGenerationOptions.Default, - new object[0], + Array.Empty(), interceptors); } @@ -1019,7 +1019,7 @@ public object CreateClassProxyWithTarget(Type classToProxy, object? target, para Type.EmptyTypes, target, ProxyGenerationOptions.Default, - new object[0], + Array.Empty(), interceptors); } @@ -1052,7 +1052,7 @@ public object CreateClassProxyWithTarget(Type classToProxy, object? target, Prox Type.EmptyTypes, target, options, - new object[0], + Array.Empty(), interceptors); } @@ -1087,7 +1087,7 @@ public object CreateClassProxyWithTarget(Type classToProxy, Type[]? additionalIn additionalInterfacesToProxy, target, options, - new object[0], + Array.Empty(), interceptors); } @@ -1465,7 +1465,7 @@ public virtual object CreateClassProxy(Type classToProxy, Type[]? additionalInte return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments); } - protected object CreateClassProxyInstance(Type proxyType, List proxyArguments, Type classToProxy, + protected static object CreateClassProxyInstance(Type proxyType, List proxyArguments, Type classToProxy, object?[]? constructorArguments) { try @@ -1495,7 +1495,7 @@ protected object CreateClassProxyInstance(Type proxyType, List proxyArg } } - protected void CheckNotGenericTypeDefinition(Type type, string argumentName) + protected static void CheckNotGenericTypeDefinition(Type type, string argumentName) { if (type != null && type.IsGenericTypeDefinition) { @@ -1505,7 +1505,7 @@ protected void CheckNotGenericTypeDefinition(Type type, string argumentName) } } - protected void CheckNotGenericTypeDefinitions(IEnumerable? types, string argumentName) + protected static void CheckNotGenericTypeDefinitions(IEnumerable? types, string argumentName) { if (types == null) { @@ -1517,7 +1517,7 @@ protected void CheckNotGenericTypeDefinitions(IEnumerable? types, string a } } - protected List BuildArgumentListForClassProxyWithTarget(object? target, ProxyGenerationOptions options, + protected static List BuildArgumentListForClassProxyWithTarget(object? target, ProxyGenerationOptions options, IInterceptor[] interceptors) { var arguments = new List(); @@ -1531,7 +1531,7 @@ protected void CheckNotGenericTypeDefinitions(IEnumerable? types, string a return arguments; } - protected List BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors) + protected static List BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors) { var arguments = new List(options.MixinData.Mixins) { interceptors }; if (options.Selector != null) From 3d6b06d5aff05482ccb2a25cbe8fc3414a3fc539 Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Wed, 18 Sep 2024 11:42:59 +0200 Subject: [PATCH 2/3] Avoid LINQ & an allocation in cache key generation & 2 more static methods --- .../Xml/Core/XmlAdapter.cs | 4 ++-- .../Contributors/ClassProxyTargetContributor.cs | 5 +---- .../ClassProxyWithTargetTargetContributor.cs | 5 +---- .../Contributors/CompositeTypeContributor.cs | 13 +++++++++++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlAdapter.cs b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlAdapter.cs index 5f500c49a7..e7af963a0a 100644 --- a/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlAdapter.cs +++ b/src/Castle.Core/Components.DictionaryAdapter/Xml/Core/XmlAdapter.cs @@ -389,14 +389,14 @@ private void HandleNodeRealized(object sender, EventArgs e) OnRealized(); } - private void AttachObservers(object value, IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property) + private static void AttachObservers(object value, IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property) { var bindingList = value as IBindingList; if (bindingList != null) bindingList.ListChanged += (s,e) => HandleListChanged(s, e, dictionaryAdapter, property); } - private void HandleListChanged(object value, ListChangedEventArgs args, IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property) + private static void HandleListChanged(object value, ListChangedEventArgs args, IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property) { var change = args.ListChangedType; var changed diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs index 8bca60f22d..cd62d31ae8 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs @@ -16,7 +16,6 @@ namespace Castle.DynamicProxy.Contributors { using System; using System.Collections.Generic; - using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -168,9 +167,7 @@ private Type GetDelegateType(MetaMethod method, ClassEmitter @class) var key = new CacheKey( typeof(Delegate), targetType, - new[] { method.MethodOnTarget.ReturnType } - .Concat(ArgumentsUtil.GetTypes(method.MethodOnTarget.GetParameters())). - ToArray(), + GetCacheKeyTypes(method), null); return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs index 98cc4da792..02447f06c7 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs @@ -16,7 +16,6 @@ namespace Castle.DynamicProxy.Contributors { using System; using System.Collections.Generic; - using System.Linq; using Castle.DynamicProxy.Generators; using Castle.DynamicProxy.Generators.Emitters; @@ -119,9 +118,7 @@ private Type GetDelegateType(MetaMethod method, ClassEmitter @class) var key = new CacheKey( typeof(Delegate), targetType, - new[] { method.MethodOnTarget.ReturnType } - .Concat(ArgumentsUtil.GetTypes(method.MethodOnTarget.GetParameters())). - ToArray(), + GetCacheKeyTypes(method), null); return scope.TypeCache.GetOrAddWithoutTakingLock(key, _ => diff --git a/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs index fc34dffbd1..6a165d0d9c 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/CompositeTypeContributor.cs @@ -137,6 +137,19 @@ private void ImplementMethod(MetaMethod method, ClassEmitter @class, } } + protected static Type[] GetCacheKeyTypes(MetaMethod method) + { + Type[] argumentTypes = ArgumentsUtil.GetTypes(method.MethodOnTarget.GetParameters()); + if (argumentTypes.Length < 1) + { + return new[] { method.MethodOnTarget.ReturnType }; + } + var types = new Type[argumentTypes.Length + 1]; + types[0] = method.MethodOnTarget.ReturnType; + argumentTypes.CopyTo(types, 1); + return types; + } + private sealed class MembersCollectorSink : IMembersCollectorSink { private readonly MetaType model; From 6f07167962c723577cbeaf6249b40294fae357d5 Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Fri, 20 Sep 2024 14:47:16 +0200 Subject: [PATCH 3/3] Undo static changes that affect the public API, they can be readded to a new major version --- ref/Castle.Core-net462.cs | 15 ++++++++------- ref/Castle.Core-net6.0.cs | 15 ++++++++------- ref/Castle.Core-netstandard2.0.cs | 15 ++++++++------- ref/Castle.Core-netstandard2.1.cs | 15 ++++++++------- src/Castle.Core/Core/Internal/InternalsVisible.cs | 2 +- .../DynamicProxy/Generators/BaseProxyGenerator.cs | 4 ++-- src/Castle.Core/DynamicProxy/ProxyGenerator.cs | 12 ++++++------ 7 files changed, 41 insertions(+), 37 deletions(-) diff --git a/ref/Castle.Core-net462.cs b/ref/Castle.Core-net462.cs index 8215e3fa63..a463161bc5 100644 --- a/ref/Castle.Core-net462.cs +++ b/ref/Castle.Core-net462.cs @@ -1945,10 +1945,11 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public static class InternalsVisible + public class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; + public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2679,6 +2680,10 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } + protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2694,6 +2699,7 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } + protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2737,12 +2743,7 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } - protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } - protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-net6.0.cs b/ref/Castle.Core-net6.0.cs index 23f83775e2..dd8a8652a4 100644 --- a/ref/Castle.Core-net6.0.cs +++ b/ref/Castle.Core-net6.0.cs @@ -1939,10 +1939,11 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public static class InternalsVisible + public class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; + public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2636,6 +2637,10 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } + protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2651,6 +2656,7 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } + protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2694,12 +2700,7 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } - protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } - protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-netstandard2.0.cs b/ref/Castle.Core-netstandard2.0.cs index eb88539729..53928d09b0 100644 --- a/ref/Castle.Core-netstandard2.0.cs +++ b/ref/Castle.Core-netstandard2.0.cs @@ -1939,10 +1939,11 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public static class InternalsVisible + public class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; + public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2633,6 +2634,10 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } + protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2648,6 +2653,7 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } + protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2691,12 +2697,7 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } - protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } - protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/ref/Castle.Core-netstandard2.1.cs b/ref/Castle.Core-netstandard2.1.cs index 9849bf07cf..40b01b56be 100644 --- a/ref/Castle.Core-netstandard2.1.cs +++ b/ref/Castle.Core-netstandard2.1.cs @@ -1939,10 +1939,11 @@ public static T[] GetTypeAttributes(System.Type type) where T : System.Attribute { } public static System.Type GetTypeConverter(System.Reflection.MemberInfo member) { } } - public static class InternalsVisible + public class InternalsVisible { public const string ToCastleCore = @"Castle.Core, PublicKey=002400000480000094000000060200000024000052534131000400000100010077F5E87030DADCCCE6902C6ADAB7A987BD69CB5819991531F560785EACFC89B6FCDDF6BB2A00743A7194E454C0273447FC6EEC36474BA8E5A3823147D214298E4F9A631B1AFEE1A51FFEAE4672D498F14B000E3D321453CDD8AC064DE7E1CF4D222B7E81F54D4FD46725370D702A05B48738CC29D09228F1AA722AE1A9CA02FB"; public const string ToDynamicProxyGenAssembly2 = @"DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7"; + public InternalsVisible() { } } } namespace Castle.Core.Logging @@ -2633,6 +2634,10 @@ public ProxyGenerator(Castle.DynamicProxy.IProxyBuilder builder) { } public ProxyGenerator(bool disableSignedModule) { } public Castle.Core.Logging.ILogger Logger { get; set; } public Castle.DynamicProxy.IProxyBuilder ProxyBuilder { get; } + protected System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } + protected void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } + protected void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } public object CreateClassProxy(System.Type classToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) { } public object CreateClassProxy(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2648,6 +2653,7 @@ public TClass CreateClassProxy(object?[]? constructorArguments, params C where TClass : class { } public TClass CreateClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, object?[]? constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors) where TClass : class { } + protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[]? additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { } public object CreateClassProxyWithTarget(System.Type classToProxy, object? target, params Castle.DynamicProxy.IInterceptor[] interceptors) { } @@ -2691,12 +2697,7 @@ public TInterface CreateInterfaceProxyWithoutTarget(params Castle.Dy where TInterface : class { } public TInterface CreateInterfaceProxyWithoutTarget(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors) where TInterface : class { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxy(Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static System.Collections.Generic.List BuildArgumentListForClassProxyWithTarget(object? target, Castle.DynamicProxy.ProxyGenerationOptions options, Castle.DynamicProxy.IInterceptor[] interceptors) { } - protected static void CheckNotGenericTypeDefinition(System.Type type, string argumentName) { } - protected static void CheckNotGenericTypeDefinitions(System.Collections.Generic.IEnumerable? types, string argumentName) { } - protected static object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List proxyArguments, System.Type classToProxy, object?[]? constructorArguments) { } - protected static System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } + protected System.Collections.Generic.List GetConstructorArguments(object? target, Castle.DynamicProxy.IInterceptor[] interceptors, Castle.DynamicProxy.ProxyGenerationOptions options) { } } public static class ProxyUtil { diff --git a/src/Castle.Core/Core/Internal/InternalsVisible.cs b/src/Castle.Core/Core/Internal/InternalsVisible.cs index 1e0b2cc75b..d735a6d27e 100644 --- a/src/Castle.Core/Core/Internal/InternalsVisible.cs +++ b/src/Castle.Core/Core/Internal/InternalsVisible.cs @@ -14,7 +14,7 @@ namespace Castle.Core.Internal { - public static class InternalsVisible + public class InternalsVisible { /// /// Constant to use when making assembly internals visible to Castle.Core diff --git a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs index 8c932676fa..3307a6e453 100644 --- a/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs @@ -134,7 +134,7 @@ protected virtual ClassEmitter BuildClassEmitter(string typeName, Type parentTyp return new ClassEmitter(Scope, typeName, parentType, interfaces); } - protected static void CheckNotGenericTypeDefinition(Type type, string argumentName) + protected void CheckNotGenericTypeDefinition(Type type, string argumentName) { if (type != null && type.IsGenericTypeDefinition) { @@ -142,7 +142,7 @@ protected static void CheckNotGenericTypeDefinition(Type type, string argumentNa } } - protected static void CheckNotGenericTypeDefinitions(IEnumerable types, string argumentName) + protected void CheckNotGenericTypeDefinitions(IEnumerable types, string argumentName) { if (types == null) { diff --git a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs index 1d4deaf393..7389bed28f 100644 --- a/src/Castle.Core/DynamicProxy/ProxyGenerator.cs +++ b/src/Castle.Core/DynamicProxy/ProxyGenerator.cs @@ -321,7 +321,7 @@ public virtual object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type return Activator.CreateInstance(generatedType, arguments.ToArray())!; } - protected static List GetConstructorArguments(object? target, IInterceptor[] interceptors, + protected List GetConstructorArguments(object? target, IInterceptor[] interceptors, ProxyGenerationOptions options) { // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments) @@ -1465,7 +1465,7 @@ public virtual object CreateClassProxy(Type classToProxy, Type[]? additionalInte return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments); } - protected static object CreateClassProxyInstance(Type proxyType, List proxyArguments, Type classToProxy, + protected object CreateClassProxyInstance(Type proxyType, List proxyArguments, Type classToProxy, object?[]? constructorArguments) { try @@ -1495,7 +1495,7 @@ protected static object CreateClassProxyInstance(Type proxyType, List p } } - protected static void CheckNotGenericTypeDefinition(Type type, string argumentName) + protected void CheckNotGenericTypeDefinition(Type type, string argumentName) { if (type != null && type.IsGenericTypeDefinition) { @@ -1505,7 +1505,7 @@ protected static void CheckNotGenericTypeDefinition(Type type, string argumentNa } } - protected static void CheckNotGenericTypeDefinitions(IEnumerable? types, string argumentName) + protected void CheckNotGenericTypeDefinitions(IEnumerable? types, string argumentName) { if (types == null) { @@ -1517,7 +1517,7 @@ protected static void CheckNotGenericTypeDefinitions(IEnumerable? types, s } } - protected static List BuildArgumentListForClassProxyWithTarget(object? target, ProxyGenerationOptions options, + protected List BuildArgumentListForClassProxyWithTarget(object? target, ProxyGenerationOptions options, IInterceptor[] interceptors) { var arguments = new List(); @@ -1531,7 +1531,7 @@ protected static void CheckNotGenericTypeDefinitions(IEnumerable? types, s return arguments; } - protected static List BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors) + protected List BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors) { var arguments = new List(options.MixinData.Mixins) { interceptors }; if (options.Selector != null)