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 46 /// <summary> 47 /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. 48 /// </summary> 49 public Type ClrType { get; private set; } 50 51 /// <summary> 52 /// Irrelevant for file descriptors; the parser for message descriptors. 53 /// </summary> 54 public MessageParser Parser { get; } 55 56 /// <summary> 57 /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order) 58 /// for fields in the message for message descriptors. 59 /// </summary> 60 public string[] PropertyNames { get; } 61 62 /// <summary> 63 /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order) 64 /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo", 65 /// there will be a "FooCase" property and a "ClearFoo" method. 66 /// </summary> 67 public string[] OneofNames { get; } 68 69 /// <summary> 70 /// The reflection information for types within this file/message descriptor. Elements may be null 71 /// if there is no corresponding generated type, e.g. for map entry types. 72 /// </summary> 73 public GeneratedClrTypeInfo[] NestedTypes { get; } 74 75 /// <summary> 76 /// The CLR types for enums within this file/message descriptor. 77 /// </summary> 78 public Type[] NestedEnums { get; } 79 80 /// <summary> 81 /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names. 82 /// Each array parameter may be null, to indicate a lack of values. 83 /// The parameter order is designed to make it feasible to format the generated code readably. 84 /// </summary> GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)85 public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) 86 { 87 NestedTypes = nestedTypes ?? EmptyCodeInfo; 88 NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; 89 ClrType = clrType; 90 Parser = parser; 91 PropertyNames = propertyNames ?? EmptyNames; 92 OneofNames = oneofNames ?? EmptyNames; 93 } 94 95 /// <summary> 96 /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums. 97 /// </summary> GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)98 public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) 99 : this(null, null, null, null, nestedEnums, nestedTypes) 100 { 101 } 102 } 103 }