public static string CSharpNamespace(this FileDescriptor desc) { // Order of looking for C# namespace: "csharp_namespace" option, proto package. // TODO: Also look for the "metadata" proto annotation: Metadata.PackageName string ns = desc?.GetOptions()?.CsharpNamespace; if (!string.IsNullOrEmpty(ns)) { return(ns); } // As a fallback, capitalize the first character of each part of the proto package. return(string.Join(".", desc.Package.Split('.').Select(x => x.ToUpperCamelCase()))); }
// Convenience methods for accessing extensions, where repeated extensions // return an empty repeated field instead of null if they're absent. internal static T GetExtension <T>(this FileDescriptor descriptor, Extension <FileOptions, T> extension) => descriptor.GetOptions() is FileOptions options?options.GetExtension(extension) : default;