Skip to content
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.
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
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -187,7 +187,8 @@ private void GenerateSerializationConstructor(ClassEmitter emitter)
typeof(object),
getValue)));
}
ctor.CodeBuilder.AddStatement(new ReturnStatement());

ctor.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private bool VerifyIfBaseImplementsGetObjectData(Type baseType, MetaType model, out MetaMethod getObjectData)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,7 +63,7 @@ public void Generate(ClassEmitter emitter)
new ThrowStatement(typeof(InvalidOperationException), "Cannot change the target of the class proxy."));
}

dynProxySetTarget.CodeBuilder.AddStatement(new ReturnStatement());
dynProxySetTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);

var getInterceptors = emitter.CreateMethod(nameof(IProxyTargetAccessor.GetInterceptors), typeof(IInterceptor[]));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void ImplementGetObjectData(ClassEmitter emitter)

CustomizeGetObjectData(getObjectData.CodeBuilder, info, getObjectData.Arguments[1], emitter);

getObjectData.CodeBuilder.AddStatement(new ReturnStatement());
getObjectData.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

protected virtual void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData,
Expand Down
8 changes: 4 additions & 4 deletions src/Castle.Core/DynamicProxy/Generators/BaseProxyGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -156,7 +156,7 @@ protected void CheckNotGenericTypeDefinitions(IEnumerable<Type> types, string ar

protected void CompleteInitCacheMethod(CodeBuilder constCodeBuilder)
{
constCodeBuilder.AddStatement(new ReturnStatement());
constCodeBuilder.AddStatement(ReturnStatement.Instance);
}

protected virtual void CreateFields(ClassEmitter emitter)
Expand Down Expand Up @@ -281,7 +281,7 @@ protected void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseCon
constructor.CodeBuilder.AddStatement(new ConstructorInvocationStatement(emitter.BaseType));
}

constructor.CodeBuilder.AddStatement(new ReturnStatement());
constructor.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

protected void GenerateConstructors(ClassEmitter emitter, Type baseType, params FieldReference[] fields)
Expand Down Expand Up @@ -339,7 +339,7 @@ protected void GenerateParameterlessConstructor(ClassEmitter emitter, Type baseC

constructor.CodeBuilder.AddStatement(new ConstructorInvocationStatement(defaultConstructor));

constructor.CodeBuilder.AddStatement(new ReturnStatement());
constructor.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

protected ConstructorEmitter GenerateStaticConstructor(ClassEmitter emitter)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -76,7 +76,7 @@ public virtual void Generate()
CodeBuilder.AddStatement(new ConstructorInvocationStatement(mainType.BaseType));
}

CodeBuilder.AddStatement(new ReturnStatement());
CodeBuilder.AddStatement(ReturnStatement.Instance);
}

CodeBuilder.Generate(builder.GetILGenerator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public virtual void Generate()
{
if (ReturnType == typeof(void))
{
CodeBuilder.AddStatement(new ReturnStatement());
CodeBuilder.AddStatement(ReturnStatement.Instance);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,14 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class EndExceptionBlockStatement : IStatement
internal sealed class EndExceptionBlockStatement : IStatement
{
public static readonly EndExceptionBlockStatement Instance = new EndExceptionBlockStatement();

private EndExceptionBlockStatement()
{
}

public void Emit(ILGenerator gen)
{
gen.EndExceptionBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,14 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class FinallyStatement : IStatement
internal sealed class FinallyStatement : IStatement
{
public static readonly FinallyStatement Instance = new FinallyStatement();

private FinallyStatement()
{
}

public void Emit(ILGenerator gen)
{
gen.BeginFinallyBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,11 +18,13 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class ReturnStatement : IStatement
internal sealed class ReturnStatement : IStatement
{
public static readonly ReturnStatement Instance = new ReturnStatement();

private readonly IExpression? expression;

public ReturnStatement()
private ReturnStatement()
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,14 @@ namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Reflection.Emit;

internal class TryStatement : IStatement
internal sealed class TryStatement : IStatement
{
public static readonly TryStatement Instance = new TryStatement();

private TryStatement()
{
}

public void Emit(ILGenerator gen)
{
gen.BeginExceptionBlock();
Expand Down
20 changes: 11 additions & 9 deletions src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -179,7 +179,7 @@ protected virtual void ImplementInvokeMethodOnTarget(ClassEmitter invocation, Pa

if (byRefArguments.Count > 0)
{
invokeMethodOnTarget.CodeBuilder.AddStatement(new TryStatement());
invokeMethodOnTarget.CodeBuilder.AddStatement(TryStatement.Instance);
}

var methodOnTargetInvocationExpression = GetCallbackMethodInvocation(invocation, args, callbackMethod, targetField, invokeMethodOnTarget);
Expand Down Expand Up @@ -225,7 +225,7 @@ protected virtual void ImplementInvokeMethodOnTarget(ClassEmitter invocation, Pa
invokeMethodOnTarget.CodeBuilder.AddStatement(setRetVal);
}

invokeMethodOnTarget.CodeBuilder.AddStatement(new ReturnStatement());
invokeMethodOnTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictionary<int, LocalReference> byRefArguments)
Expand All @@ -235,7 +235,8 @@ private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictio
return;
}

invokeMethodOnTarget.CodeBuilder.AddStatement(new FinallyStatement());
invokeMethodOnTarget.CodeBuilder.AddStatement(FinallyStatement.Instance);

foreach (var byRefArgument in byRefArguments)
{
var index = byRefArgument.Key;
Expand Down Expand Up @@ -265,7 +266,8 @@ private void AssignBackByRefArguments(MethodEmitter invokeMethodOnTarget, Dictio
new LiteralIntExpression(index),
localValue));
}
invokeMethodOnTarget.CodeBuilder.AddStatement(new EndExceptionBlockStatement());

invokeMethodOnTarget.CodeBuilder.AddStatement(EndExceptionBlockStatement.Instance);
}

private void CreateConstructor(ClassEmitter invocation)
Expand All @@ -275,7 +277,7 @@ private void CreateConstructor(ClassEmitter invocation)

var constructor = CreateConstructor(invocation, baseCtorArguments);
constructor.CodeBuilder.AddStatement(new ConstructorInvocationStatement(baseConstructor, baseCtorArguments));
constructor.CodeBuilder.AddStatement(new ReturnStatement());
constructor.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private ConstructorEmitter CreateConstructor(ClassEmitter invocation, ArgumentReference[] baseCtorArguments)
Expand All @@ -292,7 +294,7 @@ private void EmitCallThrowOnNoTarget(MethodEmitter invokeMethodOnTarget)
var throwOnNoTarget = new MethodInvocationExpression(InvocationMethods.ThrowOnNoTarget);

invokeMethodOnTarget.CodeBuilder.AddStatement(throwOnNoTarget);
invokeMethodOnTarget.CodeBuilder.AddStatement(new ReturnStatement());
invokeMethodOnTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private MethodInfo GetCallbackMethod(ClassEmitter invocation)
Expand Down Expand Up @@ -336,7 +338,7 @@ private void ImplementChangeInvocationTarget(ClassEmitter invocation, FieldRefer
changeInvocationTarget.CodeBuilder.AddStatement(
new AssignStatement(targetField,
new ConvertExpression(targetType, changeInvocationTarget.Arguments[0])));
changeInvocationTarget.CodeBuilder.AddStatement(new ReturnStatement());
changeInvocationTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private void ImplementChangeProxyTarget(ClassEmitter invocation, ClassEmitter @class)
Expand All @@ -357,7 +359,7 @@ private void ImplementChangeProxyTarget(ClassEmitter invocation, ClassEmitter @c
VirtualCall = true
});

changeProxyTarget.CodeBuilder.AddStatement(new ReturnStatement());
changeProxyTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

private void ImplementChangeProxyTargetInterface(ClassEmitter @class, ClassEmitter invocation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,22 +118,22 @@ protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, C

if (hasByRefArguments)
{
emitter.CodeBuilder.AddStatement(new TryStatement());
emitter.CodeBuilder.AddStatement(TryStatement.Instance);
}

var proceed = new MethodInvocationExpression(invocationLocal, InvocationMethods.Proceed);
emitter.CodeBuilder.AddStatement(proceed);

if (hasByRefArguments)
{
emitter.CodeBuilder.AddStatement(new FinallyStatement());
emitter.CodeBuilder.AddStatement(FinallyStatement.Instance);
}

GeneratorUtil.CopyOutAndRefParameters(dereferencedArguments, invocationLocal, MethodToOverride, emitter);

if (hasByRefArguments)
{
emitter.CodeBuilder.AddStatement(new EndExceptionBlockStatement());
emitter.CodeBuilder.AddStatement(EndExceptionBlockStatement.Instance);
}

if (MethodToOverride.ReturnType != typeof(void))
Expand Down Expand Up @@ -172,7 +172,7 @@ protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, C
}
else
{
emitter.CodeBuilder.AddStatement(new ReturnStatement());
emitter.CodeBuilder.AddStatement(ReturnStatement.Instance);
}

return emitter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
// Copyright 2004-2026 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,7 @@ protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, C

if (emitter.ReturnType == typeof(void))
{
emitter.CodeBuilder.AddStatement(new ReturnStatement());
emitter.CodeBuilder.AddStatement(ReturnStatement.Instance);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private IStatement IfNull(Type returnType)

if (returnType == typeof(void))
{
statements.AddStatement(new ReturnStatement());
statements.AddStatement(ReturnStatement.Instance);
}
else
{
Expand Down