Skip to content

Commit d2d2d96

Browse files
committed
Downgrade SelfReference to an expression & rename it
1 parent ee07fdb commit d2d2d96

10 files changed

+25
-36
lines changed

src/Castle.Core/DynamicProxy/Contributors/ClassProxySerializableContributor.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.
@@ -129,7 +129,7 @@ private void EmitCustomGetObjectData(CodeBuilder codeBuilder, ArgumentReference
129129
var getObjectData = new MethodInvocationExpression(
130130
null,
131131
FormatterServicesMethods.GetObjectData,
132-
SelfReference.Self,
132+
ThisExpression.Instance,
133133
members);
134134
codeBuilder.AddStatement(new AssignStatement(data, getObjectData));
135135

src/Castle.Core/DynamicProxy/Contributors/ClassProxyTargetContributor.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.
@@ -122,7 +122,7 @@ private MethodBuilder CreateCallbackMethod(ClassEmitter emitter, MethodInfo meth
122122

123123
callBackMethod.CodeBuilder.AddStatement(
124124
new ReturnStatement(
125-
new MethodInvocationExpression(SelfReference.Self,
125+
new MethodInvocationExpression(ThisExpression.Instance,
126126
targetMethod,
127127
callBackMethod.Arguments)));
128128

src/Castle.Core/DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.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.
@@ -119,7 +119,7 @@ private MethodInfo CreateCallbackMethod(ClassEmitter emitter, MethodInfo methodI
119119

120120
callBackMethod.CodeBuilder.AddStatement(
121121
new ReturnStatement(
122-
new MethodInvocationExpression(SelfReference.Self, targetMethod, callBackMethod.Arguments)));
122+
new MethodInvocationExpression(ThisExpression.Instance, targetMethod, callBackMethod.Arguments)));
123123

124124
return callBackMethod.MethodBuilder;
125125
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override CompositeTypeContributor GetProxyTargetContributor(INamingSco
5151
protected override ProxyTargetAccessorContributor GetProxyTargetAccessorContributor()
5252
{
5353
return new ProxyTargetAccessorContributor(
54-
getTarget: () => SelfReference.Self,
54+
getTarget: () => ThisExpression.Instance,
5555
targetType);
5656
}
5757
}

src/Castle.Core/DynamicProxy/Generators/CompositionInvocationTypeGenerator.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.
@@ -62,7 +62,7 @@ protected override void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invoca
6262
{
6363
invokeMethodOnTarget.CodeBuilder.AddStatement(
6464
new MethodInvocationExpression(
65-
SelfReference.Self,
65+
ThisExpression.Instance,
6666
InvocationMethods.CompositionInvocationEnsureValidTarget));
6767

6868
base.ImplementInvokeMethodOnTarget(invocation, parameters, invokeMethodOnTarget, targetField);

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/FieldReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public override void EmitAddress(ILGenerator gen)
6464
}
6565
else
6666
{
67-
SelfReference.Self.Emit(gen);
67+
ThisExpression.Instance.Emit(gen);
6868
gen.Emit(OpCodes.Ldflda, Reference);
6969
}
7070
}
@@ -77,7 +77,7 @@ public override void Emit(ILGenerator gen)
7777
}
7878
else
7979
{
80-
SelfReference.Self.Emit(gen);
80+
ThisExpression.Instance.Emit(gen);
8181
gen.Emit(OpCodes.Ldfld, Reference);
8282
}
8383
}
@@ -91,7 +91,7 @@ public override void EmitStore(IExpression value, ILGenerator gen)
9191
}
9292
else
9393
{
94-
SelfReference.Self.Emit(gen);
94+
ThisExpression.Instance.Emit(gen);
9595
value.Emit(gen);
9696
gen.Emit(OpCodes.Stfld, Reference);
9797
}

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/MethodInvocationExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ internal class MethodInvocationExpression : IExpression, IStatement
2626
protected readonly IExpression? instance;
2727

2828
public MethodInvocationExpression(MethodInfo method, params IExpression[] args) :
29-
this(SelfReference.Self, method, args)
29+
this(ThisExpression.Instance, method, args)
3030
{
3131
}
3232

3333
public MethodInvocationExpression(MethodEmitter method, params IExpression[] args) :
34-
this(SelfReference.Self, method.MethodBuilder, args)
34+
this(ThisExpression.Instance, method.MethodBuilder, args)
3535
{
3636
}
3737

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/SelfReference.cs renamed to src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/ThisExpression.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,17 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
2121
using System.Reflection.Emit;
2222

2323
[DebuggerDisplay("this")]
24-
internal class SelfReference : Reference
24+
internal class ThisExpression : IExpression
2525
{
26-
public static readonly SelfReference Self = new SelfReference();
26+
public static readonly ThisExpression Instance = new ThisExpression();
2727

28-
protected SelfReference()
28+
protected ThisExpression()
2929
{
3030
}
3131

32-
public override void EmitAddress(ILGenerator gen)
33-
{
34-
throw new NotSupportedException();
35-
}
36-
37-
public override void Emit(ILGenerator gen)
32+
public void Emit(ILGenerator gen)
3833
{
3934
gen.Emit(OpCodes.Ldarg_0);
4035
}
41-
42-
public override void EmitStore(IExpression value, ILGenerator gen)
43-
{
44-
// It does not make sense to assign a value to the this pointer.
45-
throw new NotSupportedException();
46-
}
4736
}
4837
}

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

Lines changed: 5 additions & 5 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.
@@ -143,7 +143,7 @@ protected virtual void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocat
143143
#endif
144144
{
145145
localValue = new ConvertExpression(paramType.GetElementType(),
146-
new MethodInvocationExpression(SelfReference.Self,
146+
new MethodInvocationExpression(ThisExpression.Instance,
147147
InvocationMethods.GetArgumentValue,
148148
new LiteralIntExpression(i)));
149149
}
@@ -170,7 +170,7 @@ protected virtual void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocat
170170
{
171171
args[i] =
172172
new ConvertExpression(paramType,
173-
new MethodInvocationExpression(SelfReference.Self,
173+
new MethodInvocationExpression(ThisExpression.Instance,
174174
InvocationMethods.GetArgumentValue,
175175
new LiteralIntExpression(i)));
176176
}
@@ -218,7 +218,7 @@ protected virtual void ImplementInvokeMethodOnTarget(AbstractTypeEmitter invocat
218218
}
219219

220220
var setRetVal =
221-
new MethodInvocationExpression(SelfReference.Self,
221+
new MethodInvocationExpression(ThisExpression.Instance,
222222
InvocationMethods.SetReturnValue,
223223
retVal);
224224

@@ -260,7 +260,7 @@ private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictio
260260

261261
invokeMethodOnTarget.CodeBuilder.AddStatement(
262262
new MethodInvocationExpression(
263-
SelfReference.Self,
263+
ThisExpression.Instance,
264264
InvocationMethods.SetArgumentValue,
265265
new LiteralIntExpression(index),
266266
localValue));

src/Castle.Core/DynamicProxy/Generators/MethodWithInvocationGenerator.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.
@@ -235,7 +235,7 @@ private IExpression[] GetCtorArguments(ClassEmitter @class, IExpression proxiedM
235235
return new[]
236236
{
237237
getTargetExpression(@class, MethodToOverride),
238-
SelfReference.Self,
238+
ThisExpression.Instance,
239239
methodInterceptors ?? interceptors,
240240
proxiedMethodTokenExpression,
241241
new ReferencesToObjectArrayExpression(dereferencedArguments)

0 commit comments

Comments
 (0)