diff options
author | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:35:27 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:35:27 +0100 |
commit | f26f8dce0279b3cd0ee9708bfca322be5c19d4f7 (patch) | |
tree | d5165af45b3bcc0243518ad766eb358f04a0980e /csharp/ProtocolBuffers/IMessage.cs | |
parent | 9134a21f27728996237010449fe9273b3bf4be78 (diff) | |
download | protobuf-f26f8dce0279b3cd0ee9708bfca322be5c19d4f7.tar.gz protobuf-f26f8dce0279b3cd0ee9708bfca322be5c19d4f7.tar.bz2 protobuf-f26f8dce0279b3cd0ee9708bfca322be5c19d4f7.zip |
The great generics revisiting.
Diffstat (limited to 'csharp/ProtocolBuffers/IMessage.cs')
-rw-r--r-- | csharp/ProtocolBuffers/IMessage.cs | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/csharp/ProtocolBuffers/IMessage.cs b/csharp/ProtocolBuffers/IMessage.cs index abb29f72..1ce18a5c 100644 --- a/csharp/ProtocolBuffers/IMessage.cs +++ b/csharp/ProtocolBuffers/IMessage.cs @@ -21,11 +21,8 @@ using Google.ProtocolBuffers.Descriptors; namespace Google.ProtocolBuffers { /// <summary> - /// Non-generic interface implemented by all Protocol Buffers messages. - /// Some members are repeated in the generic interface but with a - /// type-specific signature. Type-safe implementations - /// are encouraged to implement these non-generic members explicitly, - /// and the generic members implicitly. + /// Non-generic interface used for all parts of the API which don't require + /// any type knowledge. /// </summary> public interface IMessage { /// <summary> @@ -152,27 +149,17 @@ namespace Google.ProtocolBuffers { void WriteTo(Stream output); #endregion - #region Weakly typed members /// <summary> - /// Returns an instance of this message type with all fields set to - /// their default values. This may or may not be a singleton. This differs - /// from the DefaultInstance property of each generated message class in that this - /// method is an abstract method of IMessage whereas DefaultInstance is - /// a static property of a specific class. They return the same thing. + /// Creates a builder for the type, but in a weakly typed manner. This + /// is typically implemented by strongly typed builders by just returning + /// the result of CreateBuilderForType. /// </summary> - IMessage DefaultInstanceForType { get; } + IBuilder WeakCreateBuilderForType(); - /// <summary> - /// Constructs a new builder for a message of the same type as this message. - /// </summary> - IBuilder CreateBuilderForType(); - #endregion + IMessage WeakDefaultInstanceForType { get; } } - /// <summary> - /// Type-safe interface for all generated messages to implement. - /// </summary> - public interface IMessage<T> : IMessage where T : IMessage<T> { + public interface IMessage<TMessage> : IMessage { /// <summary> /// Returns an instance of this message type with all fields set to /// their default values. This may or may not be a singleton. This differs @@ -180,13 +167,20 @@ namespace Google.ProtocolBuffers { /// method is an abstract method of IMessage whereas DefaultInstance is /// a static property of a specific class. They return the same thing. /// </summary> - new T DefaultInstanceForType { get; } + TMessage DefaultInstanceForType { get; } + } + /// <summary> + /// Type-safe interface for all generated messages to implement. + /// </summary> + public interface IMessage<TMessage, TBuilder> : IMessage<TMessage> + where TMessage : IMessage<TMessage, TBuilder> + where TBuilder : IBuilder<TMessage, TBuilder> { #region Builders /// <summary> /// Constructs a new builder for a message of the same type as this message. /// </summary> - new IBuilder<T> CreateBuilderForType(); + TBuilder CreateBuilderForType(); #endregion } } |