Class FileDescriptor (3.23.0)

public sealed class FileDescriptor : IDescriptor

Describes a .proto file, including everything defined within. IDescriptor is implemented such that the File property returns this descriptor, and the FullName is the same as the Name.

Inheritance

object > FileDescriptor

Implements

IDescriptor

Namespace

Google.Protobuf.Reflection

Assembly

Google.Protobuf.dll

Properties

CustomOptions

[Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")]
public CustomOptions CustomOptions { get; }

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

Property Value
TypeDescription
CustomOptions

Dependencies

public IList<FileDescriptor> Dependencies { get; }
Property Value
TypeDescription
IListFileDescriptor

Unmodifiable list of this file's dependencies (imports).

DescriptorProtoFileDescriptor

public static FileDescriptor DescriptorProtoFileDescriptor { get; }

Returns the file descriptor for descriptor.proto.

Property Value
TypeDescription
FileDescriptor

The file descriptor for descriptor.proto.

Remarks

This is used for protos which take a direct dependency on descriptor.proto, typically for annotations. While descriptor.proto is a proto2 file, it is built into the Google.Protobuf runtime for reflection purposes. The messages are internal to the runtime as they would require proto2 semantics for full support, but the file descriptor is available via this property. The C# codegen in protoc automatically uses this property when it detects a dependency on descriptor.proto.

EnumTypes

public IList<EnumDescriptor> EnumTypes { get; }
Property Value
TypeDescription
IListEnumDescriptor

Unmodifiable list of top-level enum types declared in this file.

Extensions

public ExtensionCollection Extensions { get; }

Unmodifiable list of top-level extensions declared in this file. Note that some extensions may be incomplete (FieldDescriptor.Extension may be null) if this descriptor was generated using a version of protoc that did not fully support extensions in C#.

Property Value
TypeDescription
ExtensionCollection

MessageTypes

public IList<MessageDescriptor> MessageTypes { get; }
Property Value
TypeDescription
IListMessageDescriptor

Unmodifiable list of top-level message types declared in this file.

Name

public string Name { get; }
Property Value
TypeDescription
string

The file name.

Package

public string Package { get; }

The package as declared in the .proto file. This may or may not be equivalent to the .NET namespace of the generated classes.

Property Value
TypeDescription
string

PublicDependencies

public IList<FileDescriptor> PublicDependencies { get; }
Property Value
TypeDescription
IListFileDescriptor

Unmodifiable list of this file's public dependencies (public imports).

SerializedData

public ByteString SerializedData { get; }
Property Value
TypeDescription
ByteString

The original serialized binary form of this descriptor.

Services

public IList<ServiceDescriptor> Services { get; }
Property Value
TypeDescription
IListServiceDescriptor

Unmodifiable list of top-level services declared in this file.

Syntax

public Syntax Syntax { get; }

The syntax of the file

Property Value
TypeDescription
Syntax

Methods

BuildFromByteStrings(IEnumerable<ByteString>)

public static IReadOnlyList<FileDescriptor> BuildFromByteStrings(IEnumerable<ByteString> descriptorData)

Converts the given descriptor binary data into FileDescriptor objects. Note: reflection using the returned FileDescriptors is not currently supported.

Parameter
NameDescription
descriptorDataIEnumerableByteString

The binary file descriptor proto data. Must not be null, and any dependencies must come before the descriptor which depends on them. (If A depends on B, and B depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible with the order in which protoc provides descriptors to plugins.

Returns
TypeDescription
IReadOnlyListFileDescriptor

The file descriptors corresponding to descriptorData.

BuildFromByteStrings(IEnumerable<ByteString>, ExtensionRegistry)

public static IReadOnlyList<FileDescriptor> BuildFromByteStrings(IEnumerable<ByteString> descriptorData, ExtensionRegistry registry)

Converts the given descriptor binary data into FileDescriptor objects. Note: reflection using the returned FileDescriptors is not currently supported.

Parameters
NameDescription
descriptorDataIEnumerableByteString

The binary file descriptor proto data. Must not be null, and any dependencies must come before the descriptor which depends on them. (If A depends on B, and B depends on C, then the descriptors must be presented in the order C, B, A.) This is compatible with the order in which protoc provides descriptors to plugins.

registryExtensionRegistry

The extension registry to use when parsing, or null if no extensions are required.

Returns
TypeDescription
IReadOnlyListFileDescriptor

The file descriptors corresponding to descriptorData.

FindTypeByName<T>(string)

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

Finds a type (message, enum, service or extension) in the file by name. Does not find nested types.

Parameter
NameDescription
namestring

The unqualified type name to look for.

Returns
TypeDescription
T

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

Type Parameter
NameDescription
T

The type of descriptor to look for

ForceReflectionInitialization<T>()

public static void ForceReflectionInitialization<T>()

Performs initialization for the given generic type argument.

Type Parameter
NameDescription
T

The type to force initialization for.

Remarks

This method is present for the sake of AOT compilers. It allows code (whether handwritten or generated) to make calls into the reflection machinery of this library to express an intention to use that type reflectively (e.g. for JSON parsing and formatting). The call itself does almost nothing, but AOT compilers attempting to determine which generic type arguments need to be handled will spot the code path and act accordingly.

FromGeneratedCode(byte[], FileDescriptor[], GeneratedClrTypeInfo)

public static FileDescriptor FromGeneratedCode(byte[] descriptorData, FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedCodeInfo)

Creates a descriptor for generated code.

Parameters
NameDescription
descriptorDatabyte
dependenciesFileDescriptor
generatedCodeInfoGeneratedClrTypeInfo
Returns
TypeDescription
FileDescriptor
Remarks

This method is only designed to be used by the results of generating code with protoc, which creates the appropriate dependencies etc. It has to be public because the generated code is "external", but should not be called directly by end users.

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

[Obsolete("GetOption is obsolete. Use the GetOptions() method.")]
public T GetOption<T>(Extension<FileOptions, T> extension)

Gets a single value file option for this descriptor

Parameter
NameDescription
extensionExtensionFileOptions
Returns
TypeDescription
T
Type Parameter
NameDescription
T

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

[Obsolete("GetOption is obsolete. Use the GetOptions() method.")]
public RepeatedField<T> GetOption<T>(RepeatedExtension<FileOptions, T> extension)

Gets a repeated value file option for this descriptor

Parameter
NameDescription
extensionRepeatedExtensionFileOptions
Returns
TypeDescription
RepeatedField
Type Parameter
NameDescription
T

GetOptions()

public FileOptions GetOptions()

The FileOptions, 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
TypeDescription
FileOptions

ToProto()

public FileDescriptorProto ToProto()

Returns a clone of the underlying FileDescriptorProto describing this file. Note that a copy is taken every time this method is called, so clients using it frequently (and not modifying it) may want to cache the returned value.

Returns
TypeDescription
FileDescriptorProto

A protobuf representation of this file descriptor.

ToString()

public override string ToString()

Returns a string that represents this instance.

Returns
TypeDescription
string

A string that represents this instance.

Overrides