Class FileDescriptor (3.15.8)

public sealed class FileDescriptor : object, 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

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
IList<FileDescriptor>

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
IList<EnumDescriptor>

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
IList<MessageDescriptor>

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
IList<FileDescriptor>

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
IList<ServiceDescriptor>

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
descriptorDataIEnumerable<ByteString>

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
IReadOnlyList<FileDescriptor>

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
descriptorDataIEnumerable<ByteString>

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
IReadOnlyList<FileDescriptor>

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>)

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

Gets a single value file option for this descriptor

Parameter
NameDescription
extensionExtension<FileOptions, T>
Returns
TypeDescription
T
Type Parameter
NameDescription
T

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

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

Gets a repeated value file option for this descriptor

Parameter
NameDescription
extensionRepeatedExtension<FileOptions, T>
Returns
TypeDescription
RepeatedField<T>
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

ToString()

public override string ToString()

Returns a that represents this instance.

Returns
TypeDescription
String

A that represents this instance.

Explicit Interface Implementations

IDescriptor.File

FileDescriptor IDescriptor.File { get; }
Returns
TypeDescription
FileDescriptor

Implementation of IDescriptor.File - just returns this descriptor.

IDescriptor.FullName

string IDescriptor.FullName { get; }
Returns
TypeDescription
String

Implementation of IDescriptor.FullName - just returns the same as Name.