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

Make most of DynamicProxy's internals internal #505

Merged
merged 4 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ Deprecations:
- The following public members have been removed:
- `Castle.Core.Internal.Lock` (class) along with all related types and methods
- `Castle.Core.Internal.PermissionUtil.IsGranted` (method)
- `Castle.DynamicProxy.Generators.Emitters.AttributesUtil.IsAnyByRef` (method)
- `Castle.DynamicProxy.Generators.Emitters.StrongNameUtil.CanStrongNameAssembly` (property)
- `Castle.DynamicProxy.Internal.InternalsUtil` (class)
- `Castle.DynamicProxy.ModuleScope.DefineType` (method)
- `Castle.DynamicProxy.ModuleScope.GetFromCache` (method), `Castle.DynamicProxy.ModuleScope.RegisterInCache` (method), `Castle.DynamicProxy.Generators.CacheKey` (class) and a few other related methods that allowed direct access to DynamicProxy's type cache.
- all type members in `Castle.DynamicProxy.ModuleScope` that gave direct access to DynamicProxy's type cache and `ModuleBuilder`s. Only `SaveAssembly`, `LoadAssemblyIntoCache`, and members supporting these two facilities are left public.
- almost all types and type members in the `Castle.DynamicProxy.*` sub-namespaces, as most of them are intended for internal use only.

## 4.4.1 (2020-05-06)

Expand Down
994 changes: 3 additions & 991 deletions ref/Castle.Core-net45.cs

Large diffs are not rendered by default.

971 changes: 3 additions & 968 deletions ref/Castle.Core-netstandard2.0.cs

Large diffs are not rendered by default.

971 changes: 3 additions & 968 deletions ref/Castle.Core-netstandard2.1.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<StartupObject>Program</StartupObject>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Castle.Core\DynamicProxy\Generators\Emitters\StrongNameUtil.cs" Link="DynamicProxy.Tests\StrongNameUtil.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NUnit" Version="3.6.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ public class DelegateProxyTestCasE : BasePEVerifyTestCase
{
private Type GenerateProxyType<TDelegate>()
{
var scope = generator.ProxyBuilder.ModuleScope;
var proxyGenerator = new DelegateProxyGenerator(scope, typeof (TDelegate))
{
Logger = generator.ProxyBuilder.Logger
};
return proxyGenerator.GetProxyType();
var options = new ProxyGenerationOptions();
options.AddDelegateTypeMixin(typeof(TDelegate));
return generator.ProxyBuilder.CreateClassProxyType(typeof(object), null, options);
}

private T GetProxyInstance<T>(T func, params IInterceptor[] interceptors)
{
var type = GenerateProxyType<T>();
var instance = Activator.CreateInstance(type, func, interceptors);
var methodInfo = instance.GetType().GetMethod("Invoke");
return (T)(object)methodInfo.CreateDelegate(typeof(T), instance);
return (T)(object)ProxyUtil.CreateDelegateToMixin(instance, typeof(T));
}

[Test]
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;

public class ClassMembersCollector : MembersCollector
internal class ClassMembersCollector : MembersCollector
{
public ClassMembersCollector(Type targetType)
: base(targetType)
Expand Down
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;

public class ClassProxyInstanceContributor : ProxyInstanceContributor
internal class ClassProxyInstanceContributor : ProxyInstanceContributor
{
#if FEATURE_SERIALIZATION
private readonly bool delegateToBaseGetObjectData;
Expand Down
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;

public class ClassProxyTargetContributor : CompositeTypeContributor
internal 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;

public class ClassProxyWithTargetTargetContributor : CompositeTypeContributor
internal 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 @@ -24,7 +24,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Internal;

public abstract class CompositeTypeContributor : ITypeContributor
internal abstract class CompositeTypeContributor : ITypeContributor
{
protected readonly INamingScope namingScope;

Expand Down

This file was deleted.

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.SimpleAST;
using Castle.DynamicProxy.Internal;

public class DelegateTypeGenerator : IGenerator<AbstractTypeEmitter>
internal class DelegateTypeGenerator : IGenerator<AbstractTypeEmitter>
{
private const TypeAttributes DelegateFlags = TypeAttributes.Class |
TypeAttributes.Public |
Expand Down
6 changes: 3 additions & 3 deletions src/Castle.Core/DynamicProxy/Contributors/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

public delegate MethodEmitter OverrideMethodDelegate(
internal delegate MethodEmitter OverrideMethodDelegate(
string name, MethodAttributes attributes, MethodInfo methodToOverride);

public delegate Expression GetTargetExpressionDelegate(ClassEmitter @class, MethodInfo method);
internal delegate Expression GetTargetExpressionDelegate(ClassEmitter @class, MethodInfo method);

public delegate Reference GetTargetReferenceDelegate(ClassEmitter @class, MethodInfo method);
internal delegate Reference GetTargetReferenceDelegate(ClassEmitter @class, MethodInfo method);
}
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;

public class FieldReferenceComparer : IComparer<Type>
internal 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 @@ -18,7 +18,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

public class ForwardingMethodGenerator : MethodGenerator
internal class ForwardingMethodGenerator : MethodGenerator
{
private readonly GetTargetReferenceDelegate getTargetReference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Contributors
/// <summary>
/// Interface describing elements composing generated type
/// </summary>
public interface ITypeContributor
internal interface ITypeContributor
{
void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model);

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;

public class InterfaceMembersCollector : MembersCollector
internal 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;

public class InterfaceMembersOnClassCollector : MembersCollector
internal 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;

public class InterfaceProxyInstanceContributor : ProxyInstanceContributor
internal class InterfaceProxyInstanceContributor : ProxyInstanceContributor
{
protected override Reference GetTargetReference(ClassEmitter emitter)
{
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;
using Castle.DynamicProxy.Generators.Emitters;

public class InterfaceProxyTargetContributor : CompositeTypeContributor
internal class InterfaceProxyTargetContributor : CompositeTypeContributor
{
private readonly bool canChangeTarget;
private readonly Type proxyTargetType;
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;

public class InterfaceProxyWithOptionalTargetContributor : InterfaceProxyWithoutTargetContributor
internal 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;

public class InterfaceProxyWithTargetInterfaceTargetContributor : InterfaceProxyTargetContributor
internal 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 @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators;
using Castle.DynamicProxy.Generators.Emitters;

public class InterfaceProxyWithoutTargetContributor : CompositeTypeContributor
internal class InterfaceProxyWithoutTargetContributor : CompositeTypeContributor
{
private readonly GetTargetExpressionDelegate getTargetExpression;
protected bool canChangeTarget = false;
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;

public class InvocationWithDelegateContributor : IInvocationCreationContributor
internal 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;

public class InvocationWithGenericDelegateContributor : IInvocationCreationContributor
internal 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 @@ -23,7 +23,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators;
using Castle.DynamicProxy.Internal;

public abstract class MembersCollector
internal abstract class MembersCollector
{
private const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
private ILogger logger = NullLogger.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

public class MinimialisticMethodGenerator : MethodGenerator
internal class MinimialisticMethodGenerator : MethodGenerator
{
public MinimialisticMethodGenerator(MetaMethod method, OverrideMethodDelegate overrideMethod)
: base(method, overrideMethod)
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;

public class MixinContributor : CompositeTypeContributor
internal 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 @@ -21,7 +21,7 @@ namespace Castle.DynamicProxy.Contributors
using Castle.DynamicProxy.Generators.Emitters;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;

public class OptionallyForwardingMethodGenerator : MethodGenerator
internal class OptionallyForwardingMethodGenerator : MethodGenerator
{
// TODO: This class largely duplicates code from Forwarding and Minimalistic generators. Should be refactored to change that
private readonly GetTargetReferenceDelegate getTargetReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Castle.DynamicProxy.Contributors
#endif
using Castle.DynamicProxy.Tokens;

public abstract class ProxyInstanceContributor : ITypeContributor
internal abstract class ProxyInstanceContributor : ITypeContributor
{
protected readonly Type targetType;
private readonly string proxyTypeId;
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;

public class WrappedClassMembersCollector : ClassMembersCollector
internal class WrappedClassMembersCollector : ClassMembersCollector
{
public WrappedClassMembersCollector(Type type) : base(type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Castle.DynamicProxy.Generators
/// Base class that exposes the common functionalities
/// to proxy generation.
/// </summary>
public abstract class BaseProxyGenerator
internal abstract class BaseProxyGenerator
{
protected readonly Type targetType;
private readonly ModuleScope scope;
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;

public class ClassProxyGenerator : BaseProxyGenerator
internal class ClassProxyGenerator : BaseProxyGenerator
{
public ClassProxyGenerator(ModuleScope scope, Type targetType) : base(scope, targetType)
{
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;

public class ClassProxyWithTargetGenerator : BaseProxyGenerator
internal class ClassProxyWithTargetGenerator : BaseProxyGenerator
{
private readonly Type[] additionalInterfacesToProxy;

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

public class CompositionInvocationTypeGenerator : InvocationTypeGenerator
internal class CompositionInvocationTypeGenerator : InvocationTypeGenerator
{
public static readonly Type BaseType = typeof(CompositionInvocation);

Expand Down