diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 7324e3dfc638..0ba16cf96f20 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -45,7 +45,6 @@ public sealed class FieldDescriptor : DescriptorBase, IComparable @@ -70,6 +69,11 @@ public sealed class FieldDescriptor : DescriptorBase, IComparable public string JsonName { get; } + /// + /// The name of the property in the ContainingType.ClrType class. + /// + public string PropertyName { get; } + /// /// Indicates whether this field supports presence, either implicitly (e.g. due to it being a message /// type field) or explicitly via Has/Clear members. If this returns true, it is safe to call @@ -123,7 +127,7 @@ internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file, // for later. // We could trust the generated code and check whether the type of the property is // a MapField, but that feels a tad nasty. - this.propertyName = propertyName; + PropertyName = propertyName; Extension = extension; JsonName = Proto.JsonName == "" ? JsonFormatter.ToJsonName(Proto.Name) : Proto.JsonName; } @@ -436,15 +440,15 @@ private IFieldAccessor CreateAccessor() // If we're given no property name, that's because we really don't want an accessor. // This could be because it's a map message, or it could be that we're loading a FileDescriptor dynamically. // TODO: Support dynamic messages. - if (propertyName == null) + if (PropertyName == null) { return null; } - var property = ContainingType.ClrType.GetProperty(propertyName); + var property = ContainingType.ClrType.GetProperty(PropertyName); if (property == null) { - throw new DescriptorValidationException(this, $"Property {propertyName} not found in {ContainingType.ClrType}"); + throw new DescriptorValidationException(this, $"Property {PropertyName} not found in {ContainingType.ClrType}"); } return IsMap ? new MapFieldAccessor(property, this) : IsRepeated ? new RepeatedFieldAccessor(property, this)