• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 // https://developers.google.com/protocol-buffers/
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //     * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #endregion
32 using System;
33 
34 namespace Google.Protobuf.Reflection
35 {
36     /// <summary>
37     /// Extra information provided by generated code when initializing a message or file descriptor.
38     /// These are constructed as required, and are not long-lived. Hand-written code should
39     /// never need to use this type.
40     /// </summary>
41     public sealed class GeneratedClrTypeInfo
42     {
43         private static readonly string[] EmptyNames = new string[0];
44         private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0];
45         private static readonly Extension[] EmptyExtensions = new Extension[0];
46 
47         /// <summary>
48         /// Irrelevant for file descriptors; the CLR type for the message for message descriptors.
49         /// </summary>
50         public Type ClrType { get; private set; }
51 
52         /// <summary>
53         /// Irrelevant for file descriptors; the parser for message descriptors.
54         /// </summary>
55         public MessageParser Parser { get; }
56 
57         /// <summary>
58         /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order)
59         /// for fields in the message for message descriptors.
60         /// </summary>
61         public string[] PropertyNames { get; }
62 
63         /// <summary>
64         /// The extensions defined within this file/message descriptor
65         /// </summary>
66         public Extension[] Extensions { get; }
67 
68         /// <summary>
69         /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order)
70         /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo",
71         /// there will be a "FooCase" property and a "ClearFoo" method.
72         /// </summary>
73         public string[] OneofNames { get; }
74 
75         /// <summary>
76         /// The reflection information for types within this file/message descriptor. Elements may be null
77         /// if there is no corresponding generated type, e.g. for map entry types.
78         /// </summary>
79         public GeneratedClrTypeInfo[] NestedTypes { get; }
80 
81         /// <summary>
82         /// The CLR types for enums within this file/message descriptor.
83         /// </summary>
84         public Type[] NestedEnums { get; }
85 
86         /// <summary>
87         /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names.
88         /// Each array parameter may be null, to indicate a lack of values.
89         /// The parameter order is designed to make it feasible to format the generated code readably.
90         /// </summary>
GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes)91         public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes)
92         {
93             NestedTypes = nestedTypes ?? EmptyCodeInfo;
94             NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes;
95             ClrType = clrType;
96             Extensions = extensions ?? EmptyExtensions;
97             Parser = parser;
98             PropertyNames = propertyNames ?? EmptyNames;
99             OneofNames = oneofNames ?? EmptyNames;
100         }
101 
102         /// <summary>
103         /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names.
104         /// Each array parameter may be null, to indicate a lack of values.
105         /// The parameter order is designed to make it feasible to format the generated code readably.
106         /// </summary>
GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)107         public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
108             : this(clrType, parser, propertyNames, oneofNames, nestedEnums, null, nestedTypes)
109         {
110         }
111 
112         /// <summary>
113         /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types, enums, and extensions.
114         /// </summary>
GeneratedClrTypeInfo(Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes)115         public GeneratedClrTypeInfo(Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes)
116             : this(null, null, null, null, nestedEnums, extensions, nestedTypes)
117         {
118         }
119 
120         /// <summary>
121         /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums.
122         /// </summary>
GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)123         public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
124             : this(null, null, null, null, nestedEnums, nestedTypes)
125         {
126         }
127     }
128 }