Skip to content

Commit

Permalink
Merge pull request #570 from stakx/delegate-types-module-affinity
Browse files Browse the repository at this point in the history
Emit delegate types in same module as their associated proxy type
  • Loading branch information
stakx committed Jan 31, 2021
2 parents d1310e0 + 7fb29cc commit c2649e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ Bugfixes:
- Proxying certain `[Serializable]` classes produces proxy types that fail PEVerify test (@stakx, #367)
- `private protected` methods are not intercepted (@CrispyDrone, #535)
- `System.UIntPtr` unsupported (@stakx, #546)
- DynamicProxy generates two modules when proceeding from a class proxy's protected method to the target, causing an `InvalidOperationException` when saving the generated assembly to disk (@stakx, #569)

Deprecations:
- Removed support for the .NET Framework < 4.5 and .NET Standard 1.x. (@stakx, #495, #496)
Expand Down
@@ -0,0 +1,42 @@
// Copyright 2004-2021 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.Tests
{
using NUnit.Framework;

[TestFixture]
public class ClassProxyWithTargetTestCase : BasePEVerifyTestCase
{
[Test]
public void Forwards_to_protected_method()
{
var proxy = generator.CreateClassProxyWithTarget(new ClassWithProtectedMethod());
Assert.AreEqual(42, proxy.InvokeFortyTwo());
}

public class ClassWithProtectedMethod
{
public int InvokeFortyTwo()
{
return FortyTwo();
}

protected virtual int FortyTwo()
{
return 42;
}
}
}
}
Expand Up @@ -78,7 +78,8 @@ private AbstractTypeEmitter GetEmitter(ClassEmitter @class, INamingScope namingS
uniqueName,
typeof(MulticastDelegate),
Type.EmptyTypes,
DelegateFlags);
DelegateFlags,
forceUnsigned: @class.InStrongNamedModule == false);
@delegate.CopyGenericParametersFromMethod(method.Method);
return @delegate;
}
Expand Down
Expand Up @@ -34,12 +34,6 @@ public ClassEmitter(ModuleScope modulescope, string name, Type baseType, IEnumer
{
}

public ClassEmitter(ModuleScope modulescope, string name, Type baseType, IEnumerable<Type> interfaces,
TypeAttributes flags)
: this(modulescope, name, baseType, interfaces, flags, forceUnsigned: false)
{
}

public ClassEmitter(ModuleScope modulescope, string name, Type baseType, IEnumerable<Type> interfaces,
TypeAttributes flags,
bool forceUnsigned)
Expand Down

0 comments on commit c2649e3

Please sign in to comment.