Revert changes for FieldPresenceAccessor

pull/5936/head
Sydney Acksman 6 years ago
parent 29141f482c
commit 930db675ca
  1. 4
      csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
  2. 4
      csharp/src/Google.Protobuf/MessageExtensions.cs
  3. 16
      csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
  4. 2
      csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs

@ -101,7 +101,7 @@ namespace Google.Protobuf.Reflection
{
IMessage message = SampleMessages.CreateFullTestAllTypes();
var fields = message.Descriptor.Fields;
Assert.Throws<InvalidOperationException>(() => (fields[TestProtos.TestAllTypes.SingleBoolFieldNumber].Accessor as IFieldPresenceAccessor).HasValue(message));
Assert.Throws<InvalidOperationException>(() => fields[TestProtos.TestAllTypes.SingleBoolFieldNumber].Accessor.HasValue(message));
}
[Test]
@ -109,7 +109,7 @@ namespace Google.Protobuf.Reflection
{
IMessage message = new Proto2.TestAllTypes();
var fields = message.Descriptor.Fields;
var accessor = fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].Accessor as IFieldPresenceAccessor;
var accessor = fields[Proto2.TestAllTypes.OptionalBoolFieldNumber].Accessor;
Assert.False(accessor.HasValue(message));

@ -183,7 +183,7 @@ namespace Google.Protobuf
}
else if (f.FieldType == FieldType.Message || f.FieldType == FieldType.Group)
{
if ((f.Accessor as IFieldPresenceAccessor).HasValue(message))
if (f.Accessor.HasValue(message))
{
return ((IMessage)f.Accessor.GetValue(message)).IsInitialized();
}
@ -194,7 +194,7 @@ namespace Google.Protobuf
}
else if (f.IsRequired)
{
return (f.Accessor as IFieldPresenceAccessor).HasValue(message);
return f.Accessor.HasValue(message);
}
else
{

@ -58,6 +58,11 @@ namespace Google.Protobuf.Reflection
/// </summary>
object GetValue(IMessage message);
/// <summary>
/// Indicates whether the field in the specified message is set. For proto3 fields, this throws an <see cref="InvalidOperationException"/>
/// </summary>
bool HasValue(IMessage message);
/// <summary>
/// Mutator for single "simple" fields only.
/// </summary>
@ -68,15 +73,4 @@ namespace Google.Protobuf.Reflection
/// <exception cref="InvalidOperationException">The field is not a "simple" field.</exception>
void SetValue(IMessage message, object value);
}
/// <summary>
/// Allows field presence to be checked reflectively. This is implemented for all single field accessors
/// </summary>
public interface IFieldPresenceAccessor : IFieldAccessor
{
/// <summary>
/// Indicates whether the field in the specified message is set. For proto3 fields, this throws an <see cref="InvalidOperationException"/>
/// </summary>
bool HasValue(IMessage message);
}
}

@ -39,7 +39,7 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// Accessor for single fields.
/// </summary>
internal sealed class SingleFieldAccessor : FieldAccessorBase, IFieldPresenceAccessor
internal sealed class SingleFieldAccessor : FieldAccessorBase
{
// All the work here is actually done in the constructor - it creates the appropriate delegates.
// There are various cases to consider, based on the property type (message, string/bytes, or "genuine" primitive)

Loading…
Cancel
Save