aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/RpcUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ProtocolBuffers/RpcUtil.cs')
-rw-r--r--src/ProtocolBuffers/RpcUtil.cs68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/ProtocolBuffers/RpcUtil.cs b/src/ProtocolBuffers/RpcUtil.cs
index d0614a37..4659d86a 100644
--- a/src/ProtocolBuffers/RpcUtil.cs
+++ b/src/ProtocolBuffers/RpcUtil.cs
@@ -1,4 +1,5 @@
#region Copyright notice and license
+
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
@@ -30,42 +31,49 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
#endregion
using System;
-namespace Google.ProtocolBuffers {
- /// <summary>
- /// Grab-bag of utility functions useful when dealing with RPCs.
- /// </summary>
- public static class RpcUtil {
-
+namespace Google.ProtocolBuffers
+{
/// <summary>
- /// Converts an Action[IMessage] to an Action[T].
+ /// Grab-bag of utility functions useful when dealing with RPCs.
/// </summary>
- public static Action<T> SpecializeCallback<T>(Action<IMessage> action)
- where T : IMessage<T> {
- return message => action(message);
- }
+ public static class RpcUtil
+ {
+ /// <summary>
+ /// Converts an Action[IMessage] to an Action[T].
+ /// </summary>
+ public static Action<T> SpecializeCallback<T>(Action<IMessage> action)
+ where T : IMessage<T>
+ {
+ return message => action(message);
+ }
- /// <summary>
- /// Converts an Action[T] to an Action[IMessage].
- /// The generalized action will accept any message object which has
- /// the same descriptor, and will convert it to the correct class
- /// before calling the original action. However, if the generalized
- /// callback is given a message with a different descriptor, an
- /// exception will be thrown.
- /// </summary>
- public static Action<IMessage> GeneralizeCallback<TMessage, TBuilder>(Action<TMessage> action, TMessage defaultInstance)
- where TMessage : class, IMessage<TMessage, TBuilder>
- where TBuilder : IBuilder<TMessage, TBuilder> {
- return message => {
- TMessage castMessage = message as TMessage;
- if (castMessage == null) {
- castMessage = defaultInstance.CreateBuilderForType().MergeFrom(message).Build();
+ /// <summary>
+ /// Converts an Action[T] to an Action[IMessage].
+ /// The generalized action will accept any message object which has
+ /// the same descriptor, and will convert it to the correct class
+ /// before calling the original action. However, if the generalized
+ /// callback is given a message with a different descriptor, an
+ /// exception will be thrown.
+ /// </summary>
+ public static Action<IMessage> GeneralizeCallback<TMessage, TBuilder>(Action<TMessage> action,
+ TMessage defaultInstance)
+ where TMessage : class, IMessage<TMessage, TBuilder>
+ where TBuilder : IBuilder<TMessage, TBuilder>
+ {
+ return message =>
+ {
+ TMessage castMessage = message as TMessage;
+ if (castMessage == null)
+ {
+ castMessage = defaultInstance.CreateBuilderForType().MergeFrom(message).Build();
+ }
+ action(castMessage);
+ };
}
- action(castMessage);
- };
}
- }
-}
+} \ No newline at end of file