aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs')
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs42
1 files changed, 30 insertions, 12 deletions
diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
index ab7cd922..be94cb10 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -30,6 +30,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
+using Google.Protobuf.WellKnownTypes;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -43,6 +44,16 @@ namespace Google.Protobuf.Reflection
/// </summary>
public sealed class FileDescriptor : IDescriptor
{
+ // Prevent linker failures when using IL2CPP with the well-known types.
+ static FileDescriptor()
+ {
+ ForceReflectionInitialization<Syntax>();
+ ForceReflectionInitialization<NullValue>();
+ ForceReflectionInitialization<Field.Types.Cardinality>();
+ ForceReflectionInitialization<Field.Types.Kind>();
+ ForceReflectionInitialization<Value.KindOneofCase>();
+ }
+
private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo)
{
SerializedData = descriptorData;
@@ -251,17 +262,6 @@ namespace Google.Protobuf.Reflection
"Dependencies passed to FileDescriptor.BuildFrom() don't match " +
"those listed in the FileDescriptorProto.");
}
- for (int i = 0; i < proto.Dependency.Count; i++)
- {
- if (dependencies[i].Name != proto.Dependency[i])
- {
- throw new DescriptorValidationException(
- result,
- "Dependencies passed to FileDescriptor.BuildFrom() don't match " +
- "those listed in the FileDescriptorProto. Expected: " +
- proto.Dependency[i] + " but was: " + dependencies[i].Name);
- }
- }
result.CrossLink();
return result;
@@ -340,5 +340,23 @@ namespace Google.Protobuf.Reflection
/// The file descriptor for <c>descriptor.proto</c>.
/// </value>
public static FileDescriptor DescriptorProtoFileDescriptor { get { return DescriptorReflection.Descriptor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this file.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ /// <summary>
+ /// Performs initialization for the given generic type argument.
+ /// </summary>
+ /// <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.
+ /// </remarks>
+ /// <typeparam name="T">The type to force initialization for.</typeparam>
+ public static void ForceReflectionInitialization<T>() => ReflectionUtil.ForceInitialize<T>();
}
-} \ No newline at end of file
+}