Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.ExtLibs/HeuristicLab.ProtobufCS/2.4.1/ProtobufCS/src/ProtoGen/DescriptorUtil.cs @ 13957

Last change on this file since 13957 was 8295, checked in by abeham, 12 years ago

#1897:

  • Removed protocol buffers 0.9.1
  • Added protocol buffers 2.4.1
  • Updated proto processing command
File size: 4.3 KB
Line 
1#region Copyright notice and license
2
3// Protocol Buffers - Google's data interchange format
4// Copyright 2008 Google Inc.  All rights reserved.
5// http://github.com/jskeet/dotnet-protobufs/
6// Original C++/Java/Python code:
7// http://code.google.com/p/protobuf/
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13//     * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//     * Redistributions in binary form must reproduce the above
16// copyright notice, this list of conditions and the following disclaimer
17// in the documentation and/or other materials provided with the
18// distribution.
19//     * Neither the name of Google Inc. nor the names of its
20// contributors may be used to endorse or promote products derived from
21// this software without specific prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35#endregion
36
37using System;
38using Google.ProtocolBuffers.DescriptorProtos;
39using Google.ProtocolBuffers.Descriptors;
40
41namespace Google.ProtocolBuffers.ProtoGen
42{
43    /// <summary>
44    /// Utility class for determining namespaces etc.
45    /// </summary>
46    internal static class DescriptorUtil
47    {
48        internal static string GetFullUmbrellaClassName(IDescriptor descriptor)
49        {
50            CSharpFileOptions options = descriptor.File.CSharpOptions;
51            string result = options.Namespace;
52            if (result != "")
53            {
54                result += '.';
55            }
56            result += GetQualifiedUmbrellaClassName(options);
57            return "global::" + result;
58        }
59
60        /// <summary>
61        /// Evaluates the options and returns the qualified name of the umbrella class
62        /// relative to the descriptor type's namespace.  Basically concatenates the
63        /// UmbrellaNamespace + UmbrellaClassname fields.
64        /// </summary>
65        internal static string GetQualifiedUmbrellaClassName(CSharpFileOptions options)
66        {
67            string fullName = options.UmbrellaClassname;
68            if (!options.NestClasses && options.UmbrellaNamespace != "")
69            {
70                fullName = String.Format("{0}.{1}", options.UmbrellaNamespace, options.UmbrellaClassname);
71            }
72            return fullName;
73        }
74
75        internal static string GetMappedTypeName(MappedType type)
76        {
77            switch (type)
78            {
79                case MappedType.Int32:
80                    return "int";
81                case MappedType.Int64:
82                    return "long";
83                case MappedType.UInt32:
84                    return "uint";
85                case MappedType.UInt64:
86                    return "ulong";
87                case MappedType.Single:
88                    return "float";
89                case MappedType.Double:
90                    return "double";
91                case MappedType.Boolean:
92                    return "bool";
93                case MappedType.String:
94                    return "string";
95                case MappedType.ByteString:
96                    return "pb::ByteString";
97                case MappedType.Enum:
98                    return null;
99                case MappedType.Message:
100                    return null;
101                default:
102                    throw new ArgumentOutOfRangeException("Unknown mapped type " + type);
103            }
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.