Skip to content

Commit 1f7f239

Browse files
committed
Now can downgrade AsTypeReference to an expression & rename it
1 parent 16b2b3e commit 1f7f239

File tree

4 files changed

+7
-22
lines changed

4 files changed

+7
-22
lines changed

src/Castle.Core/DynamicProxy/Contributors/MixinContributor.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.
@@ -114,7 +114,7 @@ private GetTargetExpressionDelegate BuildGetTargetExpression()
114114
}
115115

116116
return (c, m) => new NullCoalescingOperatorExpression(
117-
new AsTypeReference(c.GetField("__target"), m.DeclaringType),
117+
new AsTypeExpression(c.GetField("__target"), m.DeclaringType),
118118
fields[m.DeclaringType]);
119119
}
120120

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeReference.cs renamed to src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AsTypeExpression.cs

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

2323
[DebuggerDisplay("{reference} as {type}")]
24-
internal class AsTypeReference : Reference
24+
internal class AsTypeExpression : IExpression
2525
{
2626
private readonly Reference reference;
2727
private readonly Type type;
2828

29-
public AsTypeReference(Reference reference, Type type)
30-
: base(type)
29+
public AsTypeExpression(Reference reference, Type type)
3130
{
3231
this.reference = reference;
3332
this.type = type;
3433
}
3534

36-
public override void EmitAddress(ILGenerator gen)
37-
{
38-
// It does not make sense to take the address of a cast expression.
39-
// The C# language would also forbid address-taking of the form `&(x as T)`.
40-
throw new NotSupportedException();
41-
}
42-
43-
public override void Emit(ILGenerator gen)
35+
public void Emit(ILGenerator gen)
4436
{
4537
reference.Emit(gen);
4638
gen.Emit(OpCodes.Isinst, type);
4739
}
48-
49-
public override void EmitStore(IExpression value, ILGenerator gen)
50-
{
51-
// It does not make sense to assign a value to the result of a cast expression.
52-
// The C# language would also forbid assignments of the form `(x as T) = y`.
53-
throw new NotSupportedException();
54-
}
5540
}
5641
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected override InterfaceProxyWithoutTargetContributor GetContributorForAddit
6363

6464
private IExpression GetTarget(ClassEmitter @class, MethodInfo method)
6565
{
66-
return new AsTypeReference(@class.GetField("__target"), method.DeclaringType);
66+
return new AsTypeExpression(@class.GetField("__target"), method.DeclaringType);
6767
}
6868
}
6969
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected virtual MethodInvocationExpression GetCallbackMethodInvocation(Abstrac
9696
return contributor.GetCallbackMethodInvocation(invocation, args, targetField, invokeMethodOnTarget);
9797
}
9898
var methodOnTargetInvocationExpression = new MethodInvocationExpression(
99-
new AsTypeReference(targetField, callbackMethod.DeclaringType),
99+
new AsTypeExpression(targetField, callbackMethod.DeclaringType),
100100
callbackMethod,
101101
args) { VirtualCall = true };
102102
return methodOnTargetInvocationExpression;

0 commit comments

Comments
 (0)