Show / Hide Table of Contents

Class FileDescriptor

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
System.Object
FileDescriptor
Implements
IDescriptor
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Protobuf.Reflection
Assembly: Google.Protobuf.dll
Syntax
public sealed class FileDescriptor : IDescriptor

Properties

CustomOptions

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

Declaration
public CustomOptions CustomOptions { get; }
Property Value
Type Description
CustomOptions

Dependencies

Declaration
public IList<FileDescriptor> Dependencies { get; }
Property Value
Type Description
System.Collections.Generic.IList<FileDescriptor>

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

DescriptorProtoFileDescriptor

Returns the file descriptor for descriptor.proto.

Declaration
public static FileDescriptor DescriptorProtoFileDescriptor { get; }
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

Declaration
public IList<EnumDescriptor> EnumTypes { get; }
Property Value
Type Description
System.Collections.Generic.IList<EnumDescriptor>

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

MessageTypes

Declaration
public IList<MessageDescriptor> MessageTypes { get; }
Property Value
Type Description
System.Collections.Generic.IList<MessageDescriptor>

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

Name

Declaration
public string Name { get; }
Property Value
Type Description
System.String

The file name.

Implements
IDescriptor.Name

Package

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

Declaration
public string Package { get; }
Property Value
Type Description
System.String

PublicDependencies

Declaration
public IList<FileDescriptor> PublicDependencies { get; }
Property Value
Type Description
System.Collections.Generic.IList<FileDescriptor>

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

SerializedData

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

The original serialized binary form of this descriptor.

Services

Declaration
public IList<ServiceDescriptor> Services { get; }
Property Value
Type Description
System.Collections.Generic.IList<ServiceDescriptor>

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

Methods

BuildFromByteStrings(IEnumerable<ByteString>)

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

Declaration
public static IReadOnlyList<FileDescriptor> BuildFromByteStrings(IEnumerable<ByteString> descriptorData)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<ByteString> descriptorData

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
System.Collections.Generic.IReadOnlyList<FileDescriptor>

The file descriptors corresponding to descriptorData.

FindTypeByName<T>(String)

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

Declaration
public T FindTypeByName<T>(string name)
    where T : class, IDescriptor
Parameters
Type Name Description
System.String name

The unqualified type name to look for.

Returns
Type Description
T

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

Type Parameters
Name Description
T

The type of descriptor to look for

ForceReflectionInitialization<T>()

Performs initialization for the given generic type argument.

Declaration
public static void ForceReflectionInitialization<T>()
Type Parameters
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)

Creates a descriptor for generated code.

Declaration
public static FileDescriptor FromGeneratedCode(byte[] descriptorData, FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedCodeInfo)
Parameters
Type Name Description
System.Byte[] descriptorData
FileDescriptor[] dependencies
GeneratedClrTypeInfo generatedCodeInfo
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.

ToString()

Returns a System.String that represents this instance.

Declaration
public override string ToString()
Returns
Type Description
System.String

A System.String that represents this instance.

Overrides
System.Object.ToString()

Explicit Interface Implementations

IDescriptor.File

Declaration
FileDescriptor IDescriptor.File { get; }
Returns
Type Description
FileDescriptor

Implementation of IDescriptor.File - just returns this descriptor.

Implements
IDescriptor.File

IDescriptor.FullName

Declaration
string IDescriptor.FullName { get; }
Returns
Type Description
System.String

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

Implements
IDescriptor.FullName
Back to top