Class MessageDescriptor (3.15.8)

public sealed class MessageDescriptor : DescriptorBase, IDescriptor

Describes a message type.

Inheritance

Object > DescriptorBase > MessageDescriptor

Implements

IDescriptor

Namespace

Google.Protobuf.Reflection

Assembly

Google.Protobuf.dll

Properties

ClrType

public Type ClrType { get; }

The CLR type used to represent message instances from this descriptor.

Property Value
Type Description
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

public MessageDescriptor ContainingType { get; }
Property Value
Type Description
MessageDescriptor

If this is a nested type, get the outer descriptor, otherwise null.

CustomOptions

public CustomOptions CustomOptions { get; }

The (possibly empty) set of custom options for this message.

Property Value
Type Description
CustomOptions

EnumTypes

public IList<EnumDescriptor> EnumTypes { get; }
Property Value
Type Description
IList<EnumDescriptor>

An unmodifiable list of this message type's enum types.

Extensions

public ExtensionCollection Extensions { get; }

An unmodifiable list of extensions defined in this message's scope. Note that some extensions may be incomplete (FieldDescriptor.Extension may be null) if they are declared in a file generated using a version of protoc that did not fully support extensions in C#.

Property Value
Type Description
ExtensionCollection

Fields

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

public override string Name { get; }

The brief name of the descriptor's target.

Property Value
Type Description
String
Overrides

NestedTypes

public IList<MessageDescriptor> NestedTypes { get; }
Property Value
Type Description
IList<MessageDescriptor>

An unmodifiable list of this message type's nested types.

Oneofs

public IList<OneofDescriptor> Oneofs { get; }
Property Value
Type Description
IList<OneofDescriptor>

An unmodifiable list of the "oneof" field collections in this message type. All "real" oneofs (where IsSynthetic returns false) come before synthetic ones.

Parser

public MessageParser Parser { get; }

A parser for this message type.

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.

RealOneofCount

public int RealOneofCount { get; }

The number of real "oneof" descriptors in this message type. Every element in Oneofs with an index less than this will have a IsSynthetic property value of false; every element with an index greater than or equal to this will have a IsSynthetic property value of true.

Property Value
Type Description
Int32

Methods

FindDescriptor<T>(String)

public T FindDescriptor<T>(string name)
    where T : class, IDescriptor

Finds a nested descriptor by name. The is valid for fields, nested message types, oneofs and enums.

Parameter
Name Description
name String

The unqualified name of the descriptor, e.g. "Foo"

Returns
Type Description
T

The descriptor, or null if not found.

Type Parameter
Name Description
T

FindFieldByName(String)

public FieldDescriptor FindFieldByName(String name)

Finds a field by field name.

Parameter
Name Description
name String

The unqualified name of the field (e.g. "foo").

Returns
Type Description
FieldDescriptor

The field's descriptor, or null if not found.

FindFieldByNumber(Int32)

public FieldDescriptor FindFieldByNumber(int number)

Finds a field by field number.

Parameter
Name Description
number Int32

The field number within this message type.

Returns
Type Description
FieldDescriptor

The field's descriptor, or null if not found.

GetOption<T>(Extension<MessageOptions, T>)

public T GetOption<T>(Extension<MessageOptions, T> extension)

Gets a single value message option for this descriptor

Parameter
Name Description
extension Extension<MessageOptions, T>
Returns
Type Description
T
Type Parameter
Name Description
T

GetOption<T>(RepeatedExtension<MessageOptions, T>)

public RepeatedField<T> GetOption<T>(RepeatedExtension<MessageOptions, T> extension)

Gets a repeated value message option for this descriptor

Parameter
Name Description
extension RepeatedExtension<MessageOptions, T>
Returns
Type Description
RepeatedField<T>
Type Parameter
Name Description
T

GetOptions()

public MessageOptions GetOptions()

The MessageOptions, defined in descriptor.proto. If the options message is not present (i.e. there are no options), null is returned. Custom options can be retrieved as extensions of the returned message. NOTE: A defensive copy is created each time this property is retrieved.

Returns
Type Description
MessageOptions