Class MessageDescriptor
Describes a message type.
Implements
Inherited Members
Namespace: Google.Protobuf.Reflection
Assembly: Google.Protobuf.dll
Syntax
public sealed class MessageDescriptor : DescriptorBase, IDescriptor
Properties
ClrType
The CLR type used to represent message instances from this descriptor.
Declaration
public Type ClrType { get; }
Property Value
Type | Description |
---|---|
System.Type |
Remarks
The value returned by this property will be non-null for all regular fields. However, if a message containing a map field is introspected, the list of nested messages will include an auto-generated nested key/value pair message for the field. This is not represented in any generated type, so this property will return null in such cases.
For wrapper types (StringValue and the like), the type returned here will be the generated message type, not the native type used by reflection for fields of those types. Code using reflection should call Google.Protobuf.Reflection.MessageDescriptor.IsWrapperType to determine whether a message descriptor represents a wrapper type, and handle the result appropriately.
ContainingType
Declaration
public MessageDescriptor ContainingType { get; }
Property Value
Type | Description |
---|---|
MessageDescriptor | If this is a nested type, get the outer descriptor, otherwise null. |
CustomOptions
The (possibly empty) set of custom options for this message.
Declaration
public CustomOptions CustomOptions { get; }
Property Value
Type | Description |
---|---|
CustomOptions |
EnumTypes
Declaration
public IList<EnumDescriptor> EnumTypes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<EnumDescriptor> | An unmodifiable list of this message type's enum types. |
Fields
Declaration
public MessageDescriptor.FieldCollection Fields { get; }
Property Value
Type | Description |
---|---|
MessageDescriptor.FieldCollection | A collection of fields, which can be retrieved by name or field number. |
Name
The brief name of the descriptor's target.
Declaration
public override string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
NestedTypes
Declaration
public IList<MessageDescriptor> NestedTypes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<MessageDescriptor> | An unmodifiable list of this message type's nested types. |
Oneofs
Declaration
public IList<OneofDescriptor> Oneofs { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<OneofDescriptor> | An unmodifiable list of the "oneof" field collections in this message type. |
Parser
A parser for this message type.
Declaration
public MessageParser Parser { get; }
Property Value
Type | Description |
---|---|
MessageParser |
Remarks
As MessageDescriptor is not generic, this cannot be statically typed to the relevant type, but it should produce objects of a type compatible with ClrType.
The value returned by this property will be non-null for all regular fields. However, if a message containing a map field is introspected, the list of nested messages will include an auto-generated nested key/value pair message for the field. No message parser object is created for such messages, so this property will return null in such cases.
For wrapper types (StringValue and the like), the parser returned here will be the generated message type, not the native type used by reflection for fields of those types. Code using reflection should call Google.Protobuf.Reflection.MessageDescriptor.IsWrapperType to determine whether a message descriptor represents a wrapper type, and handle the result appropriately.
Methods
FindDescriptor<T>(String)
Finds a nested descriptor by name. The is valid for fields, nested message types, oneofs and enums.
Declaration
public T FindDescriptor<T>(string name)
where T : class, IDescriptor
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The unqualified name of the descriptor, e.g. "Foo" |
Returns
Type | Description |
---|---|
T | The descriptor, or null if not found. |
Type Parameters
Name | Description |
---|---|
T |
FindFieldByName(String)
Finds a field by field name.
Declaration
public FieldDescriptor FindFieldByName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The unqualified name of the field (e.g. "foo"). |
Returns
Type | Description |
---|---|
FieldDescriptor | The field's descriptor, or null if not found. |
FindFieldByNumber(Int32)
Finds a field by field number.
Declaration
public FieldDescriptor FindFieldByNumber(int number)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | number | The field number within this message type. |
Returns
Type | Description |
---|---|
FieldDescriptor | The field's descriptor, or null if not found. |