Skip to content

Commit 310169b

Browse files
author
Martin Tamme
committed
Fixed property and event accessor handling.
1 parent a2ca6d7 commit 310169b

File tree

8 files changed

+51
-21
lines changed

8 files changed

+51
-21
lines changed

Documentation/RELEASE-NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release notes
22

3+
## Version 2.3.3
4+
5+
* Fixed property and event accessor handling.
6+
37
## Version 2.3.2
48

59
* Fixed event accessor handling.

Source/Main/NProxy.Core/Interceptors/InterceptorInvocationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void ApplyInterceptors(EventInfo eventInfo, IEnumerable<IInterceptor> in
9898
{
9999
var eventInterceptors = ApplyInterceptionBehaviors(eventInfo, interceptors);
100100

101-
foreach (var methodInfo in eventInfo.GetAllAccessors())
101+
foreach (var methodInfo in eventInfo.GetAccessorMethods())
102102
{
103103
ApplyInterceptors(methodInfo, eventInterceptors);
104104
}
@@ -113,7 +113,7 @@ private void ApplyInterceptors(PropertyInfo propertyInfo, IEnumerable<IIntercept
113113
{
114114
var propertyInterceptors = ApplyInterceptionBehaviors(propertyInfo, interceptors);
115115

116-
foreach (var methodInfo in propertyInfo.GetAllAccessors())
116+
foreach (var methodInfo in propertyInfo.GetAccessorMethods())
117117
{
118118
ApplyInterceptors(methodInfo, propertyInterceptors);
119119
}

Source/Main/NProxy.Core/Internal/Reflection/Emit/TypeBuilderExtensions.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,34 @@ public static void DefineEvent(this TypeBuilder typeBuilder,
248248
eventBuilder.SetAddOnMethod(addMethodBuilder);
249249

250250
// Build event remove method.
251-
var removeMethodInfo = eventInfo.GetRemoveMethod();
251+
var removeMethodInfo = eventInfo.GetRemoveMethod(true);
252252
var removeMethodBuilder = methodBuilderFactory(removeMethodInfo, isExplicit);
253253

254254
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
255255

256256
// Build event raise method.
257-
var raiseMethodInfo = eventInfo.GetRaiseMethod();
257+
var raiseMethodInfo = eventInfo.GetRaiseMethod(true);
258258

259259
if (raiseMethodInfo != null)
260260
{
261261
var methodBuilder = methodBuilderFactory(raiseMethodInfo, isExplicit);
262262

263263
eventBuilder.SetRaiseMethod(methodBuilder);
264264
}
265+
266+
// Build event other methods.
267+
var otherMethodInfos = eventInfo.GetOtherMethods(true);
268+
269+
// Mono returns null in case no other methods are defined.
270+
if (otherMethodInfos != null)
271+
{
272+
foreach (var otherMethodInfo in otherMethodInfos)
273+
{
274+
var methodBuilder = methodBuilderFactory(otherMethodInfo, isExplicit);
275+
276+
eventBuilder.AddOtherMethod(methodBuilder);
277+
}
278+
}
265279
}
266280

267281
/// <summary>
@@ -302,7 +316,7 @@ public static void DefineProperty(this TypeBuilder typeBuilder,
302316
null);
303317

304318
// Build property get method.
305-
var getMethodInfo = propertyInfo.GetGetMethod();
319+
var getMethodInfo = propertyInfo.GetGetMethod(true);
306320

307321
if (getMethodInfo != null)
308322
{
@@ -312,7 +326,7 @@ public static void DefineProperty(this TypeBuilder typeBuilder,
312326
}
313327

314328
// Build property set method.
315-
var setMethodInfo = propertyInfo.GetSetMethod();
329+
var setMethodInfo = propertyInfo.GetSetMethod(true);
316330

317331
if (setMethodInfo != null)
318332
{

Source/Main/NProxy.Core/Internal/Reflection/EventInfoExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public static bool CanOverride(this EventInfo eventInfo)
3939
if (eventInfo == null)
4040
throw new ArgumentNullException("eventInfo");
4141

42-
var methodInfos = eventInfo.GetAllAccessors();
42+
var methodInfos = eventInfo.GetAccessorMethods();
4343

4444
return methodInfos.All(m => m.CanOverride());
4545
}
4646

4747
/// <summary>
48-
/// Returns all accessors for the specified event.
48+
/// Returns all accessor methods for the specified event.
4949
/// </summary>
5050
/// <param name="eventInfo">The event information.</param>
51-
/// <returns>All accessors for the specified event.</returns>
52-
public static IEnumerable<MethodInfo> GetAllAccessors(this EventInfo eventInfo)
51+
/// <returns>All accessor methods for the specified event.</returns>
52+
public static IEnumerable<MethodInfo> GetAccessorMethods(this EventInfo eventInfo)
5353
{
5454
if (eventInfo == null)
5555
throw new ArgumentNullException("eventInfo");

Source/Main/NProxy.Core/Internal/Reflection/PropertyInfoExtensions.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,34 @@ public static bool CanOverride(this PropertyInfo propertyInfo)
3939
if (propertyInfo == null)
4040
throw new ArgumentNullException("propertyInfo");
4141

42-
var methodInfos = propertyInfo.GetAllAccessors();
42+
var methodInfos = propertyInfo.GetAccessorMethods();
4343

4444
return methodInfos.All(m => m.CanOverride());
4545
}
4646

4747
/// <summary>
48-
/// Returns all accessors for the specified property.
48+
/// Returns all accessor methods for the specified property.
4949
/// </summary>
5050
/// <param name="propertyInfo">The property information.</param>
51-
/// <returns>All accessors for the specified property.</returns>
52-
public static IEnumerable<MethodInfo> GetAllAccessors(this PropertyInfo propertyInfo)
51+
/// <returns>All accessor methods for the specified property.</returns>
52+
public static IEnumerable<MethodInfo> GetAccessorMethods(this PropertyInfo propertyInfo)
5353
{
5454
if (propertyInfo == null)
5555
throw new ArgumentNullException("propertyInfo");
5656

57-
return propertyInfo.GetAccessors(true);
57+
var methodInfos = new List<MethodInfo>();
58+
59+
var getMethodInfo = propertyInfo.GetGetMethod(true);
60+
61+
if (getMethodInfo != null)
62+
methodInfos.Add(getMethodInfo);
63+
64+
var setMethodInfo = propertyInfo.GetSetMethod(true);
65+
66+
if (setMethodInfo != null)
67+
methodInfos.Add(setMethodInfo);
68+
69+
return methodInfos;
5870
}
5971

6072
/// <summary>

Source/Main/NProxy.Core/ProxyTypeBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public bool IsConcreteEvent(EventInfo eventInfo)
357357
if (eventInfo == null)
358358
throw new ArgumentNullException("eventInfo");
359359

360-
var methodInfos = eventInfo.GetAllAccessors();
360+
var methodInfos = eventInfo.GetAccessorMethods();
361361

362362
return methodInfos.All(IsConcreteMethod);
363363
}
@@ -379,7 +379,7 @@ public bool IsConcreteProperty(PropertyInfo propertyInfo)
379379
if (propertyInfo == null)
380380
throw new ArgumentNullException("propertyInfo");
381381

382-
var methodInfos = propertyInfo.GetAllAccessors();
382+
var methodInfos = propertyInfo.GetAccessorMethods();
383383

384384
return methodInfos.All(IsConcreteMethod);
385385
}

Source/Test/NProxy.Core.Test/Internal/Reflection/EventInfoExtensionsTestFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public void CanOverrideTest()
4040
}
4141

4242
[Test]
43-
public void GetAllAccessorsTest()
43+
public void GetAccessorMethodsTest()
4444
{
4545
// Arrange
4646
var eventInfo = typeof (IActionEvent).GetEvent("Event");
4747

4848
// Act
49-
var methodInfos = eventInfo.GetAllAccessors();
49+
var methodInfos = eventInfo.GetAccessorMethods();
5050

5151
// Assert
5252
Assert.That(methodInfos.Count(), Is.EqualTo(2));

Source/Test/NProxy.Core.Test/Internal/Reflection/PropertyInfoExtensionsTestFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public void CanOverrideTest()
4040
}
4141

4242
[Test]
43-
public void GetAllAccessorsTest()
43+
public void GetAccessorMethodsTest()
4444
{
4545
// Arrange
4646
var propertyInfo = typeof (IObjectGetSetProperty).GetProperty("Property");
4747

4848
// Act
49-
var methodInfos = propertyInfo.GetAllAccessors();
49+
var methodInfos = propertyInfo.GetAccessorMethods();
5050

5151
// Assert
5252
Assert.That(methodInfos.Count(), Is.EqualTo(2));

0 commit comments

Comments
 (0)