From 235e04d46bdc10e4dada92ad5c1223d3ecdcf7e3 Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Wed, 16 Oct 2024 08:36:40 +0200 Subject: [PATCH] Make internal & private classes sealed where possible. Make private methods static where possible --- .../Core/Internal/InterfaceAttributeUtil.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 | 6 +++--- .../Core/StringObjectDictionaryAdapter.cs | 2 +- .../ClassProxyTargetContributor.cs | 4 ++-- .../ClassProxyWithTargetTargetContributor.cs | 4 ++-- .../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 | 4 ++-- .../DynamicProxy/DefaultProxyBuilder.cs | 8 ++++---- .../Generators/BaseClassProxyGenerator.cs | 2 +- .../Generators/BaseInterfaceProxyGenerator.cs | 4 ++-- .../Generators/BaseProxyGenerator.cs | 20 +++++++++---------- .../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 | 4 ++-- .../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 ++-- 81 files changed, 126 insertions(+), 140 deletions(-) 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/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 960fa47451..abc8730872 100644 --- a/src/Castle.Core/Core/Resource/AssemblyResource.cs +++ b/src/Castle.Core/Core/Resource/AssemblyResource.cs @@ -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/StringObjectDictionaryAdapter.cs b/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs index 23c4632cd4..326e454318 100644 --- a/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs +++ b/src/Castle.Core/Core/StringObjectDictionaryAdapter.cs @@ -178,7 +178,7 @@ public IEnumerator GetEnumerator() return ((IEnumerable) dictionary).GetEnumerator(); } - internal class EnumeratorAdapter : IEnumerator> + internal sealed class EnumeratorAdapter : IEnumerator> { private readonly StringObjectDictionaryAdapter adapter; private readonly IEnumerator keyEnumerator; diff --git a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs index e60b4d08d2..cd62d31ae8 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.cs @@ -25,7 +25,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; @@ -129,7 +129,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 d834373c3b..02447f06c7 100644 --- a/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs +++ b/src/Castle.Core/DynamicProxy/Contributors/ClassProxyWithTargetTargetContributor.cs @@ -22,7 +22,7 @@ namespace Castle.DynamicProxy.Contributors using Castle.DynamicProxy.Generators.Emitters.SimpleAST; using Castle.DynamicProxy.Tokens; - internal class ClassProxyWithTargetTargetContributor : CompositeTypeContributor + internal sealed class ClassProxyWithTargetTargetContributor : CompositeTypeContributor { private readonly Type targetType; @@ -156,7 +156,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 bbb4b41a59..62b4ca3b53 100644 --- a/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs +++ b/src/Castle.Core/DynamicProxy/CustomAttributeInfo.cs @@ -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); @@ -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 15b6584a3a..b2d826e7dc 100644 --- a/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs +++ b/src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs @@ -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++) {