Class FileDescriptor (3.27.1)

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
Type Description
CustomOptions

Dependencies

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

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

DescriptorProtoFileDescriptor

public static FileDescriptor DescriptorProtoFileDescriptor { get; }

Returns the file descriptor for descriptor.proto.

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

MessageTypes

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

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

Name

public string Name { get; }
Property Value
Type Description
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
Type Description
string

PublicDependencies

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

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

SerializedData

public ByteString SerializedData { get; }
Property Value
Type Description
ByteString

The original serialized binary form of this descriptor.

Services

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

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

Syntax

[Obsolete("Use features instead of proto syntax.")]
public Syntax Syntax { get; }

The syntax of the file.

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

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
Type Description
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
Name Description
descriptorData IEnumerableByteString

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.

registry ExtensionRegistry

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

Returns
Type Description
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
Name Description
name string

The unqualified type name to look for.

Returns
Type Description
T

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

Type Parameter
Name Description
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
Name Description
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
Name Description
descriptorData byte
dependencies FileDescriptor
generatedCodeInfo GeneratedClrTypeInfo
Returns
Type Description
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
Name Description
extension ExtensionFileOptions
Returns
Type Description
T
Type Parameter
Name Description
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
Name Description
extension RepeatedExtensionFileOptions
Returns
Type Description
RepeatedField
Type Parameter
Name Description
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
Type Description
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
Type Description
FileDescriptorProto

A protobuf representation of this file descriptor.

ToString()

public override string ToString()

Returns a string that represents this instance.

Returns
Type Description
string

A string that represents this instance.

Overrides