aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf/Reflection
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf/Reflection')
-rw-r--r--csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs3
-rw-r--r--csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs11
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs37
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldType.cs57
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs21
-rw-r--r--csharp/src/Google.Protobuf/Reflection/IDescriptor.cs11
-rw-r--r--csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs6
-rw-r--r--csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs6
-rw-r--r--csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs25
10 files changed, 157 insertions, 25 deletions
diff --git a/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs b/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
index 0300cd58..194041a8 100644
--- a/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
+++ b/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
@@ -61,6 +61,9 @@ namespace Google.Protobuf.Reflection
get { return index; }
}
+ /// <summary>
+ /// Returns the name of the entity (field, message etc) being described.
+ /// </summary>
public abstract string Name { get; }
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
index 29833c4a..b212ce96 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
@@ -51,11 +51,20 @@ namespace Google.Protobuf.Reflection
}
internal EnumValueDescriptorProto Proto { get { return proto; } }
-
+
+ /// <summary>
+ /// Returns the name of the enum value described by this object.
+ /// </summary>
public override string Name { get { return proto.Name; } }
+ /// <summary>
+ /// Returns the number associated with this enum value.
+ /// </summary>
public int Number { get { return Proto.Number; } }
+ /// <summary>
+ /// Returns the enum descriptor that this value is part of.
+ /// </summary>
public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } }
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
index 60f2bb8b..bb8e9bbb 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -93,6 +93,15 @@ namespace Google.Protobuf.Reflection
internal FieldDescriptorProto Proto { get { return proto; } }
+ /// <summary>
+ /// Returns the accessor for this field, or <c>null</c> if this descriptor does
+ /// not support reflective access.
+ /// </summary>
+ /// <remarks>
+ /// While a <see cref="FieldDescriptor"/> describes the field, it does not provide
+ /// any way of obtaining or changing the value of the field within a specific message;
+ /// that is the responsibility of the accessor.
+ /// </remarks>
public IFieldAccessor Accessor { get { return accessor; } }
/// <summary>
@@ -141,43 +150,61 @@ namespace Google.Protobuf.Reflection
default:
throw new ArgumentException("Invalid type specified");
}
- }
+ }
+ /// <summary>
+ /// Returns <c>true</c> if this field is a repeated field; <c>false</c> otherwise.
+ /// </summary>
public bool IsRepeated
{
get { return Proto.Label == FieldDescriptorProto.Types.Label.LABEL_REPEATED; }
}
+ /// <summary>
+ /// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
+ /// </summary>
public bool IsMap
{
get { return fieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry; }
}
+ // TODO(jonskeet): Check whether this is correct with proto3, where we default to packed...
+
+ /// <summary>
+ /// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
+ /// </summary>
public bool IsPacked
{
get { return Proto.Options != null && Proto.Options.Packed; }
}
/// <summary>
- /// Get the field's containing type. For extensions, this is the type being
- /// extended, not the location where the extension was defined. See
- /// <see cref="ExtensionScope" />.
+ /// Get the field's containing message type.
/// </summary>
public MessageDescriptor ContainingType
{
get { return containingType; }
}
+ /// <summary>
+ /// Returns the oneof containing this field, or <c>null</c> if it is not part of a oneof.
+ /// </summary>
public OneofDescriptor ContainingOneof
{
get { return containingOneof; }
- }
+ }
+ /// <summary>
+ /// Returns the type of the field.
+ /// </summary>
public FieldType FieldType
{
get { return fieldType; }
}
+ /// <summary>
+ /// Returns the field number declared in the proto file.
+ /// </summary>
public int FieldNumber
{
get { return Proto.Number; }
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldType.cs b/csharp/src/Google.Protobuf/Reflection/FieldType.cs
index 41fa702d..1658e34c 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldType.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldType.cs
@@ -33,28 +33,81 @@
namespace Google.Protobuf.Reflection
{
/// <summary>
- /// Enumeration of all the possible field types. The odd formatting is to make it very clear
- /// which attribute applies to which value, while maintaining a compact format.
+ /// Enumeration of all the possible field types.
/// </summary>
public enum FieldType
{
+ /// <summary>
+ /// The <c>double</c> field type.
+ /// </summary>
Double,
+ /// <summary>
+ /// The <c>float</c> field type.
+ /// </summary>
Float,
+ /// <summary>
+ /// The <c>int64</c> field type.
+ /// </summary>
Int64,
+ /// <summary>
+ /// The <c>uint64</c> field type.
+ /// </summary>
UInt64,
+ /// <summary>
+ /// The <c>int32</c> field type.
+ /// </summary>
Int32,
+ /// <summary>
+ /// The <c>fixed64</c> field type.
+ /// </summary>
Fixed64,
+ /// <summary>
+ /// The <c>fixed32</c> field type.
+ /// </summary>
Fixed32,
+ /// <summary>
+ /// The <c>bool</c> field type.
+ /// </summary>
Bool,
+ /// <summary>
+ /// The <c>string</c> field type.
+ /// </summary>
String,
+ /// <summary>
+ /// The field type used for groups (not supported in this implementation).
+ /// </summary>
Group,
+ /// <summary>
+ /// The field type used for message fields.
+ /// </summary>
Message,
+ /// <summary>
+ /// The <c>bytes</c> field type.
+ /// </summary>
Bytes,
+ /// <summary>
+ /// The <c>uint32</c> field type.
+ /// </summary>
UInt32,
+ /// <summary>
+ /// The <c>sfixed32</c> field type.
+ /// </summary>
SFixed32,
+ /// <summary>
+ /// The <c>sfixed64</c> field type.
+ /// </summary>
SFixed64,
+ /// <summary>
+ /// The <c>sint32</c> field type.
+ /// </summary>
SInt32,
+ /// <summary>
+ /// The <c>sint64</c> field type.
+ /// </summary>
SInt64,
+ /// <summary>
+ /// The field type used for enum fields.
+ /// </summary>
Enum
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
index c17c4cc4..72927702 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -51,18 +51,7 @@ namespace Google.Protobuf.Reflection
private readonly IList<FileDescriptor> dependencies;
private readonly IList<FileDescriptor> publicDependencies;
private readonly DescriptorPool pool;
-
- public enum ProtoSyntax
- {
- Proto2,
- Proto3
- }
-
- public ProtoSyntax Syntax
- {
- get { return proto.Syntax == "proto3" ? ProtoSyntax.Proto3 : ProtoSyntax.Proto2; }
- }
-
+
private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo)
{
this.descriptorData = descriptorData;
@@ -368,7 +357,13 @@ namespace Google.Protobuf.Reflection
throw new ArgumentException("Invalid embedded descriptor for \"" + proto.Name + "\".", e);
}
}
-
+
+ /// <summary>
+ /// Returns a <see cref="System.String" /> that represents this instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String" /> that represents this instance.
+ /// </returns>
public override string ToString()
{
return "FileDescriptor for " + proto.Name;
diff --git a/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs
index 6506db1b..318d58c9 100644
--- a/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs
@@ -37,8 +37,19 @@ namespace Google.Protobuf.Reflection
/// </summary>
public interface IDescriptor
{
+ /// <summary>
+ /// Returns the name of the entity (message, field etc) being described.
+ /// </summary>
string Name { get; }
+
+ /// <summary>
+ /// Returns the fully-qualified name of the entity being described.
+ /// </summary>
string FullName { get; }
+
+ /// <summary>
+ /// Returns the descriptor for the .proto file that this entity is part of.
+ /// </summary>
FileDescriptor File { get; }
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
index 3f4f05f4..f97d73ee 100644
--- a/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
@@ -30,6 +30,9 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
+using System;
+using System.Collections;
+
namespace Google.Protobuf.Reflection
{
/// <summary>
@@ -64,7 +67,7 @@ namespace Google.Protobuf.Reflection
/// 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>
+ /// <exception cref="InvalidOperationException">The field is not a "simple" field.</exception>
void SetValue(object message, object value);
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
index 0b562de1..82901f1b 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -30,7 +30,6 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
-using Google.Protobuf.Collections;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -163,6 +162,9 @@ namespace Google.Protobuf.Reflection
get { return enumTypes; }
}
+ /// <value>
+ /// An unmodifiable list of the "oneof" field collections in this message type.
+ /// </value>
public IList<OneofDescriptor> Oneofs
{
get { return oneofs; }
@@ -276,7 +278,7 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// Retrieves the descriptor for the field with the given name.
/// </summary>
- /// <param name="number">Number of the field to retrieve the descriptor for</param>
+ /// <param name="name">Name of the field to retrieve the descriptor for</param>
/// <returns>The descriptor for the given field</returns>
/// <exception cref="KeyNotFoundException">The message descriptor does not contain a field
/// with the given name</exception>
diff --git a/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs b/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs
index 8631a1c5..ff51291b 100644
--- a/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs
@@ -58,6 +58,12 @@ namespace Google.Protobuf.Reflection
clearDelegate = ReflectionUtil.CreateActionObject(clearMethod);
}
+ /// <summary>
+ /// Gets the descriptor for this oneof.
+ /// </summary>
+ /// <value>
+ /// The descriptor of the oneof.
+ /// </value>
public OneofDescriptor Descriptor { get { return descriptor; } }
/// <summary>
diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
index 8571a5eb..d51ee526 100644
--- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
@@ -32,11 +32,14 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Linq;
using Google.Protobuf.Compatibility;
namespace Google.Protobuf.Reflection
{
+ /// <summary>
+ /// Describes a "oneof" field collection in a message type: a set of
+ /// fields of which at most one can be set in any particular message.
+ /// </summary>
public sealed class OneofDescriptor : DescriptorBase
{
private readonly OneofDescriptorProto proto;
@@ -59,13 +62,33 @@ namespace Google.Protobuf.Reflection
/// </summary>
public override string Name { get { return proto.Name; } }
+ /// <summary>
+ /// Gets the message type containing this oneof.
+ /// </summary>
+ /// <value>
+ /// The message type containing this oneof.
+ /// </value>
public MessageDescriptor ContainingType
{
get { return containingType; }
}
+ /// <summary>
+ /// Gets the fields within this oneof, in declaration order.
+ /// </summary>
+ /// <value>
+ /// The fields within this oneof, in declaration order.
+ /// </value>
public IList<FieldDescriptor> Fields { get { return fields; } }
+ /// <summary>
+ /// Gets an accessor for reflective access to the values associated with the oneof
+ /// in a particular message.
+ /// </summary>
+ /// <value>
+ /// The accessor used for reflective access, or <c>null</c> if reflection is not
+ /// supported by this descriptor.
+ /// </value>
public OneofAccessor Accessor { get { return accessor; } }
internal void CrossLink()