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
@@ -0,0 +1,76 @@
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System;
using System.Diagnostics;
using System.Reflection.Emit;

internal class ConvertArgumentFromObjectExpression : IExpression
{
private readonly IExpression obj;
private Type dereferencedArgumentType;

public ConvertArgumentFromObjectExpression(IExpression obj, Type dereferencedArgumentType)
{
Debug.Assert(dereferencedArgumentType.IsByRef == false);

this.obj = obj;
this.dereferencedArgumentType = dereferencedArgumentType;
}

public void Emit(ILGenerator gen)
{
obj.Emit(gen);

if (dereferencedArgumentType == typeof(object))
{
return;
}

if (dereferencedArgumentType.IsValueType)
{
// Unbox conversion
// Assumes fromType is a boxed value
// if we can, we emit a box and ldind, otherwise, we will use unbox.any
if (LdindOpCodesDictionary.Instance[dereferencedArgumentType] != LdindOpCodesDictionary.EmptyOpCode)
{
gen.Emit(OpCodes.Unbox, dereferencedArgumentType);
OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, dereferencedArgumentType);
}
else
{
gen.Emit(OpCodes.Unbox_Any, dereferencedArgumentType);
}
}
else
{
// Possible down-cast
if (dereferencedArgumentType.IsGenericParameter)
{
gen.Emit(OpCodes.Unbox_Any, dereferencedArgumentType);
}
else if (dereferencedArgumentType.IsGenericType)
{
gen.Emit(OpCodes.Castclass, dereferencedArgumentType);
}
else if (dereferencedArgumentType.IsSubclassOf(typeof(object)))
{
gen.Emit(OpCodes.Castclass, dereferencedArgumentType);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
{
using System.Diagnostics;
using System.Reflection.Emit;

internal class ConvertArgumentToObjectExpression : IExpression
{
private readonly Reference dereferencedArgument;

public ConvertArgumentToObjectExpression(Reference dereferencedArgument)
{
Debug.Assert(dereferencedArgument.Type.IsByRef == false);

this.dereferencedArgument = dereferencedArgument;
}

public void Emit(ILGenerator gen)
{
dereferencedArgument.Emit(gen);

var dereferencedArgumentType = dereferencedArgument.Type;
if (dereferencedArgumentType.IsValueType || dereferencedArgumentType.IsGenericParameter)
{
gen.Emit(OpCodes.Box, dereferencedArgumentType);
}
}
}
}
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 @@ -59,23 +59,5 @@ public override void EmitStore(IExpression value, ILGenerator gen)
value.Emit(gen);
OpCodeUtil.EmitStoreIndirectOpCodeForType(gen, Type);
}

public static Reference WrapIfByRef(Reference reference)
{
return reference.Type.IsByRef ? new IndirectReference(reference) : reference;
}

// TODO: Better name
public static Reference[] WrapIfByRef(Reference[] references)
{
var result = new Reference[references.Length];

for (var i = 0; i < references.Length; i++)
{
result[i] = WrapIfByRef(references[i]);
}

return result;
}
}
}

This file was deleted.

96 changes: 0 additions & 96 deletions src/Castle.Core/DynamicProxy/Generators/GeneratorUtil.cs

This file was deleted.

Loading