Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark DynamicProxy's internal classes as sealed #544

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Internal;
using Castle.DynamicProxy.Tokens;

internal class ClassProxyTargetContributor : CompositeTypeContributor
internal sealed class ClassProxyTargetContributor : CompositeTypeContributor
{
private readonly IList<MethodInfo> methodsToSkip;
private readonly Type targetType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 IList<MethodInfo> methodsToSkip;
private readonly Type targetType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Castle.DynamicProxy.Contributors
using System;
using System.Collections.Generic;

internal class FieldReferenceComparer : IComparer<Type>
internal sealed class FieldReferenceComparer : IComparer<Type>
{
public int Compare(Type x, Type y)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
using Castle.DynamicProxy.Tokens;

internal class InterfaceProxyInstanceContributor : ProxyInstanceContributor
internal sealed class InterfaceProxyInstanceContributor : ProxyInstanceContributor
{
protected override Reference GetTargetReference(ClassEmitter emitter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Castle.DynamicProxy.Contributors
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<Type> empty = new List<Type>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Internal;

internal class WrappedClassMembersCollector : ClassMembersCollector
internal sealed class WrappedClassMembersCollector : ClassMembersCollector
{
public WrappedClassMembersCollector(Type type) : base(type)
{
Expand Down Expand Up @@ -52,13 +52,13 @@ protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGener
return new MetaMethod(method, method, isStandalone, accepted, hasTarget: true);
}

protected bool IsGeneratedByTheCompiler(FieldInfo field)
private bool IsGeneratedByTheCompiler(FieldInfo field)
{
// for example fields backing autoproperties
return field.IsDefined(typeof(CompilerGeneratedAttribute));
}

protected virtual bool IsOKToBeOnProxy(FieldInfo field)
private bool IsOKToBeOnProxy(FieldInfo field)
{
return IsGeneratedByTheCompiler(field);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.Core/DynamicProxy/Generators/CacheKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Castle.DynamicProxy.Generators
using Castle.DynamicProxy.Internal;
using Castle.DynamicProxy.Serialization;

internal class ClassProxyGenerator : BaseProxyGenerator
internal sealed class ClassProxyGenerator : BaseProxyGenerator
{
public ClassProxyGenerator(ModuleScope scope, Type targetType, Type[] interfaces, ProxyGenerationOptions options)
: base(scope, targetType, interfaces, options)
Expand Down Expand Up @@ -94,8 +94,7 @@ protected override Type GenerateType(string name, INamingScope namingScope)
return proxyType;
}

protected virtual IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContributor> contributors,
INamingScope namingScope)
private IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContributor> contributors, INamingScope namingScope)
{
var methodsToSkip = new List<MethodInfo>();
var proxyInstance = new ClassProxyInstanceContributor(targetType, methodsToSkip, interfaces, ProxyTypeConstants.Class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Castle.DynamicProxy.Generators
using Castle.DynamicProxy.Internal;
using Castle.DynamicProxy.Serialization;

internal class ClassProxyWithTargetGenerator : BaseProxyGenerator
internal sealed class ClassProxyWithTargetGenerator : BaseProxyGenerator
{
public ClassProxyWithTargetGenerator(ModuleScope scope, Type targetType, Type[] interfaces,
ProxyGenerationOptions options)
Expand All @@ -37,8 +37,7 @@ public ClassProxyWithTargetGenerator(ModuleScope scope, Type targetType, Type[]
EnsureDoesNotImplementIProxyTargetAccessor(targetType, "targetType");
}

protected virtual IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContributor> contributors,
INamingScope namingScope)
private IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContributor> contributors, INamingScope namingScope)
{
var methodsToSkip = new List<MethodInfo>();
var proxyInstance = new ClassProxyWithTargetInstanceContributor(targetType, methodsToSkip, interfaces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Generators
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
using Castle.DynamicProxy.Internal;

internal class DelegateTypeGenerator : IGenerator<AbstractTypeEmitter>
internal sealed class DelegateTypeGenerator : IGenerator<AbstractTypeEmitter>
{
private const TypeAttributes DelegateFlags = TypeAttributes.Class |
TypeAttributes.Public |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators.Emitters

using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

internal abstract class ArgumentsUtil
internal static class ArgumentsUtil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to at least get these static changes in. Shows how long ago these classes were first written to use abstract to prevent instantiation of the class.

{
public static Expression[] ConvertArgumentReferenceToExpression(ArgumentReference[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,8 +81,7 @@ internal bool InStrongNamedModule
get { return StrongNameUtil.IsAssemblySigned(TypeBuilder.Assembly); }
}

protected virtual IEnumerable<Type> InitializeGenericArgumentsFromBases(ref Type baseType,
IEnumerable<Type> interfaces)
private IEnumerable<Type> InitializeGenericArgumentsFromBases(ref Type baseType, IEnumerable<Type> interfaces)
{
if (baseType != null && baseType.IsGenericTypeDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.CodeBuilders

using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

internal class ConstructorCodeBuilder : AbstractCodeBuilder
internal sealed class ConstructorCodeBuilder : AbstractCodeBuilder
{
private readonly Type baseType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.CodeBuilders
{
using System.Reflection.Emit;

internal class MethodCodeBuilder : AbstractCodeBuilder
internal sealed class MethodCodeBuilder : AbstractCodeBuilder
{
public MethodCodeBuilder(ILGenerator generator) : base(generator)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Castle.DynamicProxy.Generators.Emitters

internal delegate GenericTypeParameterBuilder[] ApplyGenArgs(string[] argumentNames);

internal class GenericUtil
internal sealed class GenericUtil
{
public static GenericTypeParameterBuilder[] CopyGenericArguments(
MethodInfo methodToCopyGenericsFrom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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 GenericTypeParameterBuilder[] genericTypeParams;
Expand All @@ -35,7 +35,7 @@ internal class MethodEmitter : IMemberEmitter

private MethodCodeBuilder codebuilder;

protected internal MethodEmitter(MethodBuilder builder)
private MethodEmitter(MethodBuilder builder)
{
this.builder = builder;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public ArgumentReference[] Arguments
get { return arguments; }
}

public virtual MethodCodeBuilder CodeBuilder
public MethodCodeBuilder CodeBuilder
{
get
{
Expand Down Expand Up @@ -129,7 +129,7 @@ public void SetParameters(Type[] paramTypes)
ArgumentsUtil.InitializeArgumentsByPosition(arguments, MethodBuilder.IsStatic);
}

public virtual void EnsureValidCodeBlock()
public void EnsureValidCodeBlock()
{
if (ImplementedByRuntime == false && CodeBuilder.IsEmpty)
{
Expand All @@ -138,7 +138,7 @@ public virtual void EnsureValidCodeBlock()
}
}

public virtual void Generate()
public void Generate()
{
if (ImplementedByRuntime)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Generators.Emitters
using System.Reflection;
using System.Reflection.Emit;

internal abstract class OpCodeUtil
internal static class OpCodeUtil
{
/// <summary>
/// Emits a load indirect opcode of the appropriate type for a value or object reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class AddressOfReferenceExpression : Expression
internal sealed class AddressOfReferenceExpression : Expression
{
private readonly Reference reference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class AssignArgumentStatement : Statement
internal sealed class AssignArgumentStatement : Statement
{
private readonly ArgumentReference argument;
private readonly Expression expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class AssignArrayStatement : Statement
internal sealed class AssignArrayStatement : Statement
{
private readonly Reference targetArray;
private readonly int targetPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class AssignStatement : Statement
internal sealed class AssignStatement : Statement
{
private readonly Expression expression;
private readonly Reference target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST

using Castle.DynamicProxy.Internal;

internal class BindDelegateExpression : Expression
internal sealed class BindDelegateExpression : Expression
{
private readonly ConstructorInfo delegateCtor;
private readonly MethodInfo methodToBindTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading