Skip to content

Commit ee07fdb

Browse files
committed
ProxyTargetAccessorContributor.getTarget does not need a reference
1 parent 6294ad5 commit ee07fdb

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

src/Castle.Core/DynamicProxy/Contributors/ProxyTargetAccessorContributor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ namespace Castle.DynamicProxy.Contributors
2525
/// </summary>
2626
internal sealed class ProxyTargetAccessorContributor : ITypeContributor
2727
{
28-
private readonly Func<Reference> getTargetReference;
28+
private readonly Func<IExpression> getTarget;
2929
private readonly Type targetType;
3030

31-
public ProxyTargetAccessorContributor(Func<Reference> getTargetReference, Type targetType)
31+
public ProxyTargetAccessorContributor(Func<IExpression> getTarget, Type targetType)
3232
{
33-
this.getTargetReference = getTargetReference;
33+
this.getTarget = getTarget;
3434
this.targetType = targetType;
3535
}
3636

@@ -41,17 +41,17 @@ public void CollectElementsToProxy(IProxyGenerationHook hook, MetaType model)
4141
public void Generate(ClassEmitter emitter)
4242
{
4343
var interceptorsField = emitter.GetField("__interceptors");
44-
var targetReference = getTargetReference();
44+
var target = getTarget();
4545

4646
var dynProxyGetTarget = emitter.CreateMethod(nameof(IProxyTargetAccessor.DynProxyGetTarget), typeof(object));
4747

4848
dynProxyGetTarget.CodeBuilder.AddStatement(
49-
new ReturnStatement(new ConvertExpression(typeof(object), targetType, targetReference)));
49+
new ReturnStatement(new ConvertExpression(typeof(object), targetType, target)));
5050

5151
var dynProxySetTarget = emitter.CreateMethod(nameof(IProxyTargetAccessor.DynProxySetTarget), typeof(void), typeof(object));
5252

5353
// we can only change the target of the interface proxy
54-
if (targetReference is FieldReference targetField)
54+
if (target is FieldReference targetField)
5555
{
5656
dynProxySetTarget.CodeBuilder.AddStatement(
5757
new AssignStatement(targetField,

src/Castle.Core/DynamicProxy/Generators/ClassProxyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(INamingSco
5151
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
5252
{
5353
return new ProxyTargetAccessorContributor(
54-
getTargetReference: () => SelfReference.Self,
54+
getTarget: () => SelfReference.Self,
5555
targetType);
5656
}
5757
}

src/Castle.Core/DynamicProxy/Generators/ClassProxyWithTargetGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(INamingSco
6565
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
6666
{
6767
return new ProxyTargetAccessorContributor(
68-
getTargetReference: () => targetField,
68+
getTarget: () => targetField,
6969
targetType);
7070
}
7171

src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(Type proxy
4040
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
4141
{
4242
return new ProxyTargetAccessorContributor(
43-
getTargetReference: () => targetField,
43+
getTarget: () => targetField,
4444
proxyTargetType);
4545
}
4646

src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithTargetInterfaceGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(Type proxy
4444
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
4545
{
4646
return new ProxyTargetAccessorContributor(
47-
getTargetReference: () => targetField,
47+
getTarget: () => targetField,
4848
proxyTargetType);
4949
}
5050

src/Castle.Core/DynamicProxy/Generators/InterfaceProxyWithoutTargetGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(Type proxy
4141
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
4242
{
4343
return new ProxyTargetAccessorContributor(
44-
getTargetReference: () => targetField,
44+
getTarget: () => targetField,
4545
proxyTargetType);
4646
}
4747

0 commit comments

Comments
 (0)