diff options
author | Jon Skeet <jonskeet@google.com> | 2015-07-01 14:47:03 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-07-09 08:24:49 +0100 |
commit | 78ea98f56f7a0a028e378aee6394549707e199bc (patch) | |
tree | b3275e8d8b01528dc58af6ec0877c4ee79cd1b54 /csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs | |
parent | 3805b43009d35422bed85c56aaf2d6ce4d007fe5 (diff) | |
download | protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.tar.gz protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.tar.bz2 protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.zip |
Implement reflection properly for fields.
- FieldAccessorTable is now non-generic
- We don't have a static field per message type in the umbrella class. (Message descriptors are accessed via the file descriptor.)
- Removed the "descriptor assigner" complication from the descriptor fixup; without extensions, we don't need it
- MapField implements IDictionary (more tests would be good...)
- RepeatedField implements IList (more tests would be good)
- Use expression trees to build accessors. (Will need to test this on various platforms... probably need a fallback strategy just using reflection directly.)
- Added FieldDescriptor.IsMap
- Added tests for reflection with generated messages
Changes to generated code coming in next commit.
Diffstat (limited to 'csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs')
-rw-r--r-- | csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs b/csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs index 61838543..77e7146d 100644 --- a/csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs +++ b/csharp/src/ProtocolBuffers/FieldAccess/IFieldAccessor.cs @@ -30,39 +30,41 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
+using Google.Protobuf.Descriptors;
+
namespace Google.Protobuf.FieldAccess
{
/// <summary>
- /// Allows fields to be reflectively accessed in a smart manner.
- /// The property descriptors for each field are created once and then cached.
- /// In addition, this interface holds knowledge of repeated fields, builders etc.
+ /// Allows fields to be reflectively accessed.
/// </summary>
- internal interface IFieldAccessor<T> where T : IMessage<T>
+ public interface IFieldAccessor
{
/// <summary>
- /// Indicates whether the specified message contains the field. For primitive fields
- /// declared in proto3-syntax messages, this simply checks whether the value is the default one.
+ /// Returns the descriptor associated with this field.
/// </summary>
- /// <exception cref="InvalidOperationException">The field is a repeated field, or a single primitive field.</exception>
- bool HasValue(T message);
+ FieldDescriptor Descriptor { get; }
/// <summary>
/// Clears the field in the specified message. (For repeated fields,
/// this clears the list.)
/// </summary>
- void Clear(T message);
+ void Clear(object message);
/// <summary>
/// Fetches the field value. For repeated values, this will be an
- /// <see cref="IList"/> implementation.
+ /// <see cref="IList"/> implementation. For map values, this will be an
+ /// <see cref="IDictionary"/> implementation.
/// </summary>
- object GetValue(T message);
+ object GetValue(object message);
/// <summary>
- /// Mutator for single fields only. (Repeated fields must be mutated
- /// by fetching the list, then mutating that.)
+ /// Mutator for single "simple" fields only.
/// </summary>
- /// <exception cref="InvalidOperationException">The field is a repeated field.</exception>
- void SetValue(T message, object value);
+ /// <remarks>
+ /// Repeated fields are mutated by fetching the value and manipulating it as a list.
+ /// Map fields are mutated by fetching the value and manipulating it as a dictionary.
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">The field is not a "simple" field, or the message is frozen.</exception>
+ void SetValue(object message, object value);
}
}
\ No newline at end of file |