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.
Implements
IDescriptorNamespace
Google.Protobuf.ReflectionAssembly
Google.Protobuf.dll
Properties
CustomOptions
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 |
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 | |
---|---|
Type | Description |
FileDescriptor | The file descriptor for |
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 |
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 | |
---|---|
Type | Description |
ExtensionCollection |
MessageTypes
public IList<MessageDescriptor> MessageTypes { get; }
Property Value | |
---|---|
Type | Description |
IList<MessageDescriptor> | 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 |
IList<FileDescriptor> | 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 |
IList<ServiceDescriptor> | Unmodifiable list of top-level services declared in this file. |
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 | IEnumerable<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 | |
---|---|
Type | Description |
IReadOnlyList<FileDescriptor> | The file descriptors corresponding to |
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 | IEnumerable<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. |
registry | ExtensionRegistry The extension registry to use when parsing, or null if no extensions are required. |
Returns | |
---|---|
Type | Description |
IReadOnlyList<FileDescriptor> | The file descriptors corresponding to |
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. |
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 |
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 | |
---|---|
Name | Description |
extension | Extension<FileOptions, T> |
Returns | |
---|---|
Type | Description |
T |
Type Parameter | |
---|---|
Name | Description |
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 | |
---|---|
Name | Description |
extension | RepeatedExtension<FileOptions, T> |
Returns | |
---|---|
Type | Description |
RepeatedField<T> |
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 |
ToString()
public override string ToString()
Returns a that represents this instance.
Returns | |
---|---|
Type | Description |
String | A that represents this instance. |
Explicit Interface Implementations
IDescriptor.File
FileDescriptor IDescriptor.File { get; }
Returns | |
---|---|
Type | Description |
FileDescriptor | Implementation of IDescriptor.File - just returns this descriptor. |
IDescriptor.FullName
string IDescriptor.FullName { get; }
Returns | |
---|---|
Type | Description |
String | Implementation of IDescriptor.FullName - just returns the same as Name. |