Skip to content

Commit

Permalink
Fixed property and event accessor handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Tamme committed Apr 12, 2014
1 parent a2ca6d7 commit 310169b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Documentation/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release notes

## Version 2.3.3

* Fixed property and event accessor handling.

## Version 2.3.2

* Fixed event accessor handling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void ApplyInterceptors(EventInfo eventInfo, IEnumerable<IInterceptor> in
{
var eventInterceptors = ApplyInterceptionBehaviors(eventInfo, interceptors);

foreach (var methodInfo in eventInfo.GetAllAccessors())
foreach (var methodInfo in eventInfo.GetAccessorMethods())
{
ApplyInterceptors(methodInfo, eventInterceptors);
}
Expand All @@ -113,7 +113,7 @@ private void ApplyInterceptors(PropertyInfo propertyInfo, IEnumerable<IIntercept
{
var propertyInterceptors = ApplyInterceptionBehaviors(propertyInfo, interceptors);

foreach (var methodInfo in propertyInfo.GetAllAccessors())
foreach (var methodInfo in propertyInfo.GetAccessorMethods())
{
ApplyInterceptors(methodInfo, propertyInterceptors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,34 @@ public static void DefineEvent(this TypeBuilder typeBuilder,
eventBuilder.SetAddOnMethod(addMethodBuilder);

// Build event remove method.
var removeMethodInfo = eventInfo.GetRemoveMethod();
var removeMethodInfo = eventInfo.GetRemoveMethod(true);
var removeMethodBuilder = methodBuilderFactory(removeMethodInfo, isExplicit);

eventBuilder.SetRemoveOnMethod(removeMethodBuilder);

// Build event raise method.
var raiseMethodInfo = eventInfo.GetRaiseMethod();
var raiseMethodInfo = eventInfo.GetRaiseMethod(true);

if (raiseMethodInfo != null)
{
var methodBuilder = methodBuilderFactory(raiseMethodInfo, isExplicit);

eventBuilder.SetRaiseMethod(methodBuilder);
}

// Build event other methods.
var otherMethodInfos = eventInfo.GetOtherMethods(true);

// Mono returns null in case no other methods are defined.
if (otherMethodInfos != null)
{
foreach (var otherMethodInfo in otherMethodInfos)
{
var methodBuilder = methodBuilderFactory(otherMethodInfo, isExplicit);

eventBuilder.AddOtherMethod(methodBuilder);
}
}
}

/// <summary>
Expand Down Expand Up @@ -302,7 +316,7 @@ public static void DefineProperty(this TypeBuilder typeBuilder,
null);

// Build property get method.
var getMethodInfo = propertyInfo.GetGetMethod();
var getMethodInfo = propertyInfo.GetGetMethod(true);

if (getMethodInfo != null)
{
Expand All @@ -312,7 +326,7 @@ public static void DefineProperty(this TypeBuilder typeBuilder,
}

// Build property set method.
var setMethodInfo = propertyInfo.GetSetMethod();
var setMethodInfo = propertyInfo.GetSetMethod(true);

if (setMethodInfo != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public static bool CanOverride(this EventInfo eventInfo)
if (eventInfo == null)
throw new ArgumentNullException("eventInfo");

var methodInfos = eventInfo.GetAllAccessors();
var methodInfos = eventInfo.GetAccessorMethods();

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

/// <summary>
/// Returns all accessors for the specified event.
/// Returns all accessor methods for the specified event.
/// </summary>
/// <param name="eventInfo">The event information.</param>
/// <returns>All accessors for the specified event.</returns>
public static IEnumerable<MethodInfo> GetAllAccessors(this EventInfo eventInfo)
/// <returns>All accessor methods for the specified event.</returns>
public static IEnumerable<MethodInfo> GetAccessorMethods(this EventInfo eventInfo)
{
if (eventInfo == null)
throw new ArgumentNullException("eventInfo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,34 @@ public static bool CanOverride(this PropertyInfo propertyInfo)
if (propertyInfo == null)
throw new ArgumentNullException("propertyInfo");

var methodInfos = propertyInfo.GetAllAccessors();
var methodInfos = propertyInfo.GetAccessorMethods();

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

/// <summary>
/// Returns all accessors for the specified property.
/// Returns all accessor methods for the specified property.
/// </summary>
/// <param name="propertyInfo">The property information.</param>
/// <returns>All accessors for the specified property.</returns>
public static IEnumerable<MethodInfo> GetAllAccessors(this PropertyInfo propertyInfo)
/// <returns>All accessor methods for the specified property.</returns>
public static IEnumerable<MethodInfo> GetAccessorMethods(this PropertyInfo propertyInfo)
{
if (propertyInfo == null)
throw new ArgumentNullException("propertyInfo");

return propertyInfo.GetAccessors(true);
var methodInfos = new List<MethodInfo>();

var getMethodInfo = propertyInfo.GetGetMethod(true);

if (getMethodInfo != null)
methodInfos.Add(getMethodInfo);

var setMethodInfo = propertyInfo.GetSetMethod(true);

if (setMethodInfo != null)
methodInfos.Add(setMethodInfo);

return methodInfos;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Source/Main/NProxy.Core/ProxyTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public bool IsConcreteEvent(EventInfo eventInfo)
if (eventInfo == null)
throw new ArgumentNullException("eventInfo");

var methodInfos = eventInfo.GetAllAccessors();
var methodInfos = eventInfo.GetAccessorMethods();

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

var methodInfos = propertyInfo.GetAllAccessors();
var methodInfos = propertyInfo.GetAccessorMethods();

return methodInfos.All(IsConcreteMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void CanOverrideTest()
}

[Test]
public void GetAllAccessorsTest()
public void GetAccessorMethodsTest()
{
// Arrange
var eventInfo = typeof (IActionEvent).GetEvent("Event");

// Act
var methodInfos = eventInfo.GetAllAccessors();
var methodInfos = eventInfo.GetAccessorMethods();

// Assert
Assert.That(methodInfos.Count(), Is.EqualTo(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void CanOverrideTest()
}

[Test]
public void GetAllAccessorsTest()
public void GetAccessorMethodsTest()
{
// Arrange
var propertyInfo = typeof (IObjectGetSetProperty).GetProperty("Property");

// Act
var methodInfos = propertyInfo.GetAllAccessors();
var methodInfos = propertyInfo.GetAccessorMethods();

// Assert
Assert.That(methodInfos.Count(), Is.EqualTo(2));
Expand Down

0 comments on commit 310169b

Please sign in to comment.