Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Mar 27, 2018
1 parent 7b19d20 commit 9c05c35
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,40 @@ internal static class ReflectionUtil
internal static readonly Type[] EmptyTypes = new Type[0];

/// <summary>
/// Creates a delegate which will cast the argument to the appropriate method target type,
/// Creates a delegate which will cast the argument to the type that declares the method,
/// call the method on it, then convert the result to object.
/// </summary>
/// <param name="method">The method to create a delegate for, which must be declared in an IMessage
/// implementation.</param>
internal static Func<IMessage, object> CreateFuncIMessageObject(MethodInfo method) =>
GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageObject(method);

/// <summary>
/// Creates a delegate which will cast the argument to the appropriate method target type,
/// Creates a delegate which will cast the argument to the type that declares the method,
/// call the method on it, then convert the result to the specified type. The method is expected
/// to actually return an enum (because of where we're calling it - for oneof cases). Sometimes that
/// means we need some extra work to perform conversions.
/// </summary>
/// <param name="method">The method to create a delegate for, which must be declared in an IMessage
/// implementation.</param>
internal static Func<IMessage, int> CreateFuncIMessageInt32(MethodInfo method) =>
GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageInt32(method);

/// <summary>
/// Creates a delegate which will execute the given method after casting the first argument to
/// the target type of the method, and the second argument to the first parameter type of the method.
/// the type that declares the method, and the second argument to the first parameter type of the method.
/// </summary>
/// <param name="method">The method to create a delegate for, which must be declared in an IMessage
/// implementation.</param>
internal static Action<IMessage, object> CreateActionIMessageObject(MethodInfo method) =>
GetReflectionHelper(method.DeclaringType, method.GetParameters()[0].ParameterType).CreateActionIMessageObject(method);

/// <summary>
/// Creates a delegate which will execute the given method after casting the first argument to
/// the target type of the method.
/// type that declares the method.
/// </summary>
/// <param name="method">The method to create a delegate for, which must be declared in an IMessage
/// implementation.</param>
internal static Action<IMessage> CreateActionIMessage(MethodInfo method) =>
GetReflectionHelper(method.DeclaringType, typeof(object)).CreateActionIMessage(method);

Expand Down Expand Up @@ -174,4 +182,4 @@ public enum SampleEnum
// Public to make the reflection simpler.
public static SampleEnum SampleEnumMethod() => SampleEnum.X;
}
}
}

0 comments on commit 9c05c35

Please sign in to comment.