Commit 9f37de96 authored by Jon Skeet's avatar Jon Skeet

Changing reflection namespace (part 1)

- Move types into Google.Protobuf.Reflection
- Change codegen to reflect that in generated types

Generated code changes coming in part 2
parent 24f8626c
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.Descriptors; using Google.Protobuf.Reflection;
using UnitTest.Issues.TestProtos; using UnitTest.Issues.TestProtos;
using NUnit.Framework; using NUnit.Framework;
......
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
<Compile Include="Collections\MapFieldTest.cs" /> <Compile Include="Collections\MapFieldTest.cs" />
<Compile Include="Collections\RepeatedFieldTest.cs" /> <Compile Include="Collections\RepeatedFieldTest.cs" />
<Compile Include="JsonFormatterTest.cs" /> <Compile Include="JsonFormatterTest.cs" />
<Compile Include="Reflection\DescriptorsTest.cs" />
<Compile Include="SampleEnum.cs" /> <Compile Include="SampleEnum.cs" />
<Compile Include="SampleMessages.cs" /> <Compile Include="SampleMessages.cs" />
<Compile Include="TestProtos\MapUnittestProto3.cs" /> <Compile Include="TestProtos\MapUnittestProto3.cs" />
...@@ -89,7 +90,6 @@ ...@@ -89,7 +90,6 @@
<Compile Include="TestProtos\UnittestIssues.cs" /> <Compile Include="TestProtos\UnittestIssues.cs" />
<Compile Include="TestProtos\UnittestProto3.cs" /> <Compile Include="TestProtos\UnittestProto3.cs" />
<Compile Include="DeprecatedMemberTest.cs" /> <Compile Include="DeprecatedMemberTest.cs" />
<Compile Include="DescriptorsTest.cs" />
<Compile Include="IssuesTest.cs" /> <Compile Include="IssuesTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestCornerCases.cs" /> <Compile Include="TestCornerCases.cs" />
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#endregion #endregion
using System; using System;
using Google.Protobuf.FieldAccess; using Google.Protobuf.Reflection;
namespace Google.Protobuf namespace Google.Protobuf
{ {
......
...@@ -34,8 +34,7 @@ using System; ...@@ -34,8 +34,7 @@ using System;
using System.Collections; using System.Collections;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using Google.Protobuf.Descriptors; using Google.Protobuf.Reflection;
using Google.Protobuf.FieldAccess;
namespace Google.Protobuf namespace Google.Protobuf
{ {
......
...@@ -62,45 +62,46 @@ ...@@ -62,45 +62,46 @@
<Compile Include="Collections\RepeatedField.cs" /> <Compile Include="Collections\RepeatedField.cs" />
<Compile Include="DescriptorProtos\DescriptorProtoFile.cs" /> <Compile Include="DescriptorProtos\DescriptorProtoFile.cs" />
<Compile Include="DescriptorProtos\PartialClasses.cs" /> <Compile Include="DescriptorProtos\PartialClasses.cs" />
<Compile Include="Descriptors\DescriptorBase.cs" />
<Compile Include="Descriptors\DescriptorPool.cs" />
<Compile Include="Descriptors\DescriptorUtil.cs" />
<Compile Include="Descriptors\DescriptorValidationException.cs" />
<Compile Include="Descriptors\EnumDescriptor.cs" />
<Compile Include="Descriptors\EnumValueDescriptor.cs" />
<Compile Include="Descriptors\FieldDescriptor.cs" />
<Compile Include="Descriptors\FieldType.cs" />
<Compile Include="Descriptors\FileDescriptor.cs" />
<Compile Include="Descriptors\OneofDescriptor.cs" />
<Compile Include="Descriptors\IDescriptor.cs" />
<Compile Include="Descriptors\MessageDescriptor.cs" />
<Compile Include="Descriptors\MethodDescriptor.cs" />
<Compile Include="Descriptors\PackageDescriptor.cs" />
<Compile Include="Descriptors\ServiceDescriptor.cs" />
<Compile Include="FieldAccess\MapFieldAccessor.cs" />
<Compile Include="FieldCodec.cs" /> <Compile Include="FieldCodec.cs" />
<Compile Include="FrameworkPortability.cs" /> <Compile Include="FrameworkPortability.cs" />
<Compile Include="Freezable.cs" /> <Compile Include="Freezable.cs" />
<Compile Include="JsonFormatter.cs" /> <Compile Include="JsonFormatter.cs" />
<Compile Include="MessageExtensions.cs" /> <Compile Include="MessageExtensions.cs" />
<Compile Include="FieldAccess\FieldAccessorBase.cs" />
<Compile Include="FieldAccess\ReflectionUtil.cs" />
<Compile Include="FieldAccess\RepeatedFieldAccessor.cs" />
<Compile Include="FieldAccess\SingleFieldAccessor.cs" />
<Compile Include="FieldAccess\IFieldAccessor.cs" />
<Compile Include="FieldAccess\FieldAccessorTable.cs" />
<Compile Include="FieldAccess\OneofAccessor.cs" />
<Compile Include="IMessage.cs" /> <Compile Include="IMessage.cs" />
<Compile Include="InvalidProtocolBufferException.cs" /> <Compile Include="InvalidProtocolBufferException.cs" />
<Compile Include="LimitedInputStream.cs" /> <Compile Include="LimitedInputStream.cs" />
<Compile Include="MessageParser.cs" /> <Compile Include="MessageParser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflection\DescriptorBase.cs" />
<Compile Include="Reflection\DescriptorPool.cs" />
<Compile Include="Reflection\DescriptorUtil.cs" />
<Compile Include="Reflection\DescriptorValidationException.cs" />
<Compile Include="Reflection\EnumDescriptor.cs" />
<Compile Include="Reflection\EnumValueDescriptor.cs" />
<Compile Include="Reflection\FieldAccessorBase.cs" />
<Compile Include="Reflection\FieldAccessorTable.cs" />
<Compile Include="Reflection\FieldDescriptor.cs" />
<Compile Include="Reflection\FieldType.cs" />
<Compile Include="Reflection\FileDescriptor.cs" />
<Compile Include="Reflection\IDescriptor.cs" />
<Compile Include="Reflection\IFieldAccessor.cs" />
<Compile Include="Reflection\MapFieldAccessor.cs" />
<Compile Include="Reflection\MessageDescriptor.cs" />
<Compile Include="Reflection\MethodDescriptor.cs" />
<Compile Include="Reflection\OneofAccessor.cs" />
<Compile Include="Reflection\OneofDescriptor.cs" />
<Compile Include="Reflection\PackageDescriptor.cs" />
<Compile Include="Reflection\ReflectionUtil.cs" />
<Compile Include="Reflection\RepeatedFieldAccessor.cs" />
<Compile Include="Reflection\ServiceDescriptor.cs" />
<Compile Include="Reflection\SingleFieldAccessor.cs" />
<Compile Include="ThrowHelper.cs" /> <Compile Include="ThrowHelper.cs" />
<Compile Include="WireFormat.cs" /> <Compile Include="WireFormat.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Google.Protobuf.nuspec" /> <None Include="Google.Protobuf.nuspec" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.DescriptorProtos; namespace Google.Protobuf.Reflection
{
namespace Google.Protobuf.Descriptors /// <summary>
{ /// Base class for nearly all descriptors, providing common functionality.
/// <summary> /// </summary>
/// Base class for nearly all descriptors, providing common functionality. public abstract class DescriptorBase : IDescriptor
/// </summary> {
public abstract class DescriptorBase : IDescriptor private readonly FileDescriptor file;
{ private readonly string fullName;
private readonly FileDescriptor file; private readonly int index;
private readonly string fullName;
private readonly int index; internal DescriptorBase(FileDescriptor file, string fullName, int index)
{
internal DescriptorBase(FileDescriptor file, string fullName, int index) this.file = file;
{ this.fullName = fullName;
this.file = file; this.index = index;
this.fullName = fullName; }
this.index = index;
} /// <value>
/// The index of this descriptor within its parent descriptor.
/// <value> /// </value>
/// The index of this descriptor within its parent descriptor. /// <remarks>
/// </value> /// This returns the index of this descriptor within its parent, for
/// <remarks> /// this descriptor's type. (There can be duplicate values for different
/// This returns the index of this descriptor within its parent, for /// types, e.g. one enum type with index 0 and one message type with index 0.)
/// this descriptor's type. (There can be duplicate values for different /// </remarks>
/// types, e.g. one enum type with index 0 and one message type with index 0.) public int Index
/// </remarks> {
public int Index get { return index; }
{ }
get { return index; }
} public abstract string Name { get; }
public abstract string Name { get; } /// <summary>
/// The fully qualified name of the descriptor's target.
/// <summary> /// </summary>
/// The fully qualified name of the descriptor's target. public string FullName
/// </summary> {
public string FullName get { return fullName; }
{ }
get { return fullName; }
} /// <value>
/// The file this descriptor was declared in.
/// <value> /// </value>
/// The file this descriptor was declared in. public FileDescriptor File
/// </value> {
public FileDescriptor File get { return file; }
{ }
get { return file; } }
}
}
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Internal class containing utility methods when working with descriptors. /// Internal class containing utility methods when working with descriptors.
/// </summary> /// </summary>
internal static class DescriptorUtil internal static class DescriptorUtil
{ {
/// <summary> /// <summary>
/// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert
/// arrays. /// arrays.
/// </summary> /// </summary>
internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index); internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index);
/// <summary> /// <summary>
/// Converts the given array into a read-only list, applying the specified conversion to /// Converts the given array into a read-only list, applying the specified conversion to
/// each input element. /// each input element.
/// </summary> /// </summary>
internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput>(IList<TInput> input, internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput>(IList<TInput> input,
IndexedConverter<TInput, TOutput> IndexedConverter<TInput, TOutput>
converter) converter)
{ {
TOutput[] array = new TOutput[input.Count]; TOutput[] array = new TOutput[input.Count];
for (int i = 0; i < array.Length; i++) for (int i = 0; i < array.Length; i++)
{ {
array[i] = converter(input[i], i); array[i] = converter(input[i], i);
} }
return new ReadOnlyCollection<TOutput>(array); return new ReadOnlyCollection<TOutput>(array);
} }
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Thrown when building descriptors fails because the source DescriptorProtos /// Thrown when building descriptors fails because the source DescriptorProtos
/// are not valid. /// are not valid.
/// </summary> /// </summary>
public sealed class DescriptorValidationException : Exception public sealed class DescriptorValidationException : Exception
{ {
private readonly String name; private readonly String name;
private readonly string description; private readonly string description;
/// <value> /// <value>
/// The full name of the descriptor where the error occurred. /// The full name of the descriptor where the error occurred.
/// </value> /// </value>
public String ProblemSymbolName public String ProblemSymbolName
{ {
get { return name; } get { return name; }
} }
/// <value> /// <value>
/// A human-readable description of the error. (The Message property /// A human-readable description of the error. (The Message property
/// is made up of the descriptor's name and this description.) /// is made up of the descriptor's name and this description.)
/// </value> /// </value>
public string Description public string Description
{ {
get { return description; } get { return description; }
} }
internal DescriptorValidationException(IDescriptor problemDescriptor, string description) : internal DescriptorValidationException(IDescriptor problemDescriptor, string description) :
base(problemDescriptor.FullName + ": " + description) base(problemDescriptor.FullName + ": " + description)
{ {
// Note that problemDescriptor may be partially uninitialized, so we // Note that problemDescriptor may be partially uninitialized, so we
// don't want to expose it directly to the user. So, we only provide // don't want to expose it directly to the user. So, we only provide
// the name and the original proto. // the name and the original proto.
name = problemDescriptor.FullName; name = problemDescriptor.FullName;
this.description = description; this.description = description;
} }
internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) : internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) :
base(problemDescriptor.FullName + ": " + description, cause) base(problemDescriptor.FullName + ": " + description, cause)
{ {
name = problemDescriptor.FullName; name = problemDescriptor.FullName;
this.description = description; this.description = description;
} }
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using Google.Protobuf.DescriptorProtos; using Google.Protobuf.DescriptorProtos;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Descriptor for an enum type in a .proto file. /// Descriptor for an enum type in a .proto file.
/// </summary> /// </summary>
public sealed class EnumDescriptor : DescriptorBase public sealed class EnumDescriptor : DescriptorBase
{ {
private readonly EnumDescriptorProto proto; private readonly EnumDescriptorProto proto;
private readonly MessageDescriptor containingType; private readonly MessageDescriptor containingType;
private readonly IList<EnumValueDescriptor> values; private readonly IList<EnumValueDescriptor> values;
internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index) internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index)
: base(file, file.ComputeFullName(parent, proto.Name), index) : base(file, file.ComputeFullName(parent, proto.Name), index)
{ {
this.proto = proto; this.proto = proto;
containingType = parent; containingType = parent;
if (proto.Value.Count == 0) if (proto.Value.Count == 0)
{ {
// We cannot allow enums with no values because this would mean there // We cannot allow enums with no values because this would mean there
// would be no valid default value for fields of this type. // would be no valid default value for fields of this type.
throw new DescriptorValidationException(this, "Enums must contain at least one value."); throw new DescriptorValidationException(this, "Enums must contain at least one value.");
} }
values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value, values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value,
(value, i) => new EnumValueDescriptor(value, file, this, i)); (value, i) => new EnumValueDescriptor(value, file, this, i));
File.DescriptorPool.AddSymbol(this); File.DescriptorPool.AddSymbol(this);
} }
internal EnumDescriptorProto Proto { get { return proto; } } internal EnumDescriptorProto Proto { get { return proto; } }
/// <summary> /// <summary>
/// The brief name of the descriptor's target. /// The brief name of the descriptor's target.
/// </summary> /// </summary>
public override string Name { get { return proto.Name; } } public override string Name { get { return proto.Name; } }
/// <value> /// <value>
/// If this is a nested type, get the outer descriptor, otherwise null. /// If this is a nested type, get the outer descriptor, otherwise null.
/// </value> /// </value>
public MessageDescriptor ContainingType public MessageDescriptor ContainingType
{ {
get { return containingType; } get { return containingType; }
} }
/// <value> /// <value>
/// An unmodifiable list of defined value descriptors for this enum. /// An unmodifiable list of defined value descriptors for this enum.
/// </value> /// </value>
public IList<EnumValueDescriptor> Values public IList<EnumValueDescriptor> Values
{ {
get { return values; } get { return values; }
} }
/// <summary> /// <summary>
/// Finds an enum value by number. If multiple enum values have the /// Finds an enum value by number. If multiple enum values have the
/// same number, this returns the first defined value with that number. /// same number, this returns the first defined value with that number.
/// If there is no value for the given number, this returns <c>null</c>. /// If there is no value for the given number, this returns <c>null</c>.
/// </summary> /// </summary>
public EnumValueDescriptor FindValueByNumber(int number) public EnumValueDescriptor FindValueByNumber(int number)
{ {
return File.DescriptorPool.FindEnumValueByNumber(this, number); return File.DescriptorPool.FindEnumValueByNumber(this, number);
} }
/// <summary> /// <summary>
/// Finds an enum value by name. /// Finds an enum value by name.
/// </summary> /// </summary>
/// <param name="name">The unqualified name of the value (e.g. "FOO").</param> /// <param name="name">The unqualified name of the value (e.g. "FOO").</param>
/// <returns>The value's descriptor, or null if not found.</returns> /// <returns>The value's descriptor, or null if not found.</returns>
public EnumValueDescriptor FindValueByName(string name) public EnumValueDescriptor FindValueByName(string name)
{ {
return File.DescriptorPool.FindSymbol<EnumValueDescriptor>(FullName + "." + name); return File.DescriptorPool.FindSymbol<EnumValueDescriptor>(FullName + "." + name);
} }
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.DescriptorProtos; using Google.Protobuf.DescriptorProtos;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Descriptor for a single enum value within an enum in a .proto file. /// Descriptor for a single enum value within an enum in a .proto file.
/// </summary> /// </summary>
public sealed class EnumValueDescriptor : DescriptorBase public sealed class EnumValueDescriptor : DescriptorBase
{ {
private readonly EnumDescriptor enumDescriptor; private readonly EnumDescriptor enumDescriptor;
private readonly EnumValueDescriptorProto proto; private readonly EnumValueDescriptorProto proto;
internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file, internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file,
EnumDescriptor parent, int index) EnumDescriptor parent, int index)
: base(file, parent.FullName + "." + proto.Name, index) : base(file, parent.FullName + "." + proto.Name, index)
{ {
this.proto = proto; this.proto = proto;
enumDescriptor = parent; enumDescriptor = parent;
file.DescriptorPool.AddSymbol(this); file.DescriptorPool.AddSymbol(this);
file.DescriptorPool.AddEnumValueByNumber(this); file.DescriptorPool.AddEnumValueByNumber(this);
} }
internal EnumValueDescriptorProto Proto { get { return proto; } } internal EnumValueDescriptorProto Proto { get { return proto; } }
public override string Name { get { return proto.Name; } } public override string Name { get { return proto.Name; } }
public int Number { get { return Proto.Number; } } public int Number { get { return Proto.Number; } }
public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } } public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } }
} }
} }
\ No newline at end of file
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
using System; using System;
using System.Reflection; using System.Reflection;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf.FieldAccess namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Base class for field accessors. /// Base class for field accessors.
......
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf.Reflection
namespace Google.Protobuf.FieldAccess {
{ /// <summary>
/// <summary> /// Provides access to fields in generated messages via reflection.
/// Provides access to fields in generated messages via reflection. /// </summary>
/// </summary> public sealed class FieldAccessorTable
public sealed class FieldAccessorTable {
{ private readonly ReadOnlyCollection<IFieldAccessor> accessors;
private readonly ReadOnlyCollection<IFieldAccessor> accessors; private readonly ReadOnlyCollection<OneofAccessor> oneofs;
private readonly ReadOnlyCollection<OneofAccessor> oneofs; private readonly MessageDescriptor descriptor;
private readonly MessageDescriptor descriptor;
/// <summary>
/// <summary> /// Constructs a FieldAccessorTable for a particular message class.
/// Constructs a FieldAccessorTable for a particular message class. /// Only one FieldAccessorTable should be constructed per class.
/// Only one FieldAccessorTable should be constructed per class. /// </summary>
/// </summary> /// <param name="type">The CLR type for the message.</param>
/// <param name="type">The CLR type for the message.</param> /// <param name="descriptor">The type's descriptor</param>
/// <param name="descriptor">The type's descriptor</param> /// <param name="propertyNames">The Pascal-case names of all the field-based properties in the message.</param>
/// <param name="propertyNames">The Pascal-case names of all the field-based properties in the message.</param> public FieldAccessorTable(Type type, MessageDescriptor descriptor, string[] propertyNames, string[] oneofPropertyNames)
public FieldAccessorTable(Type type, MessageDescriptor descriptor, string[] propertyNames, string[] oneofPropertyNames) {
{ this.descriptor = descriptor;
this.descriptor = descriptor; var accessorsArray = new IFieldAccessor[descriptor.Fields.Count];
var accessorsArray = new IFieldAccessor[descriptor.Fields.Count]; for (int i = 0; i < accessorsArray.Length; i++)
for (int i = 0; i < accessorsArray.Length; i++) {
{ var field = descriptor.Fields[i];
var field = descriptor.Fields[i]; var name = propertyNames[i];
var name = propertyNames[i]; accessorsArray[i] =
accessorsArray[i] = field.IsMap ? new MapFieldAccessor(type, name, field)
field.IsMap ? new MapFieldAccessor(type, name, field) : field.IsRepeated ? new RepeatedFieldAccessor(type, name, field)
: field.IsRepeated ? new RepeatedFieldAccessor(type, name, field) : (IFieldAccessor) new SingleFieldAccessor(type, name, field);
: (IFieldAccessor) new SingleFieldAccessor(type, name, field); }
} accessors = new ReadOnlyCollection<IFieldAccessor>(accessorsArray);
accessors = new ReadOnlyCollection<IFieldAccessor>(accessorsArray); var oneofsArray = new OneofAccessor[descriptor.Oneofs.Count];
var oneofsArray = new OneofAccessor[descriptor.Oneofs.Count]; for (int i = 0; i < oneofsArray.Length; i++)
for (int i = 0; i < oneofsArray.Length; i++) {
{ var oneof = descriptor.Oneofs[i];
var oneof = descriptor.Oneofs[i]; oneofsArray[i] = new OneofAccessor(type, oneofPropertyNames[i], oneof);
oneofsArray[i] = new OneofAccessor(type, oneofPropertyNames[i], oneof); }
} oneofs = new ReadOnlyCollection<OneofAccessor>(oneofsArray);
oneofs = new ReadOnlyCollection<OneofAccessor>(oneofsArray); }
}
// TODO: Validate the name here... should possibly make this type a more "general reflection access" type,
// TODO: Validate the name here... should possibly make this type a more "general reflection access" type, // bearing in mind the oneof parts to come as well.
// bearing in mind the oneof parts to come as well. /// <summary>
/// <summary> /// Returns all of the field accessors for the message type.
/// Returns all of the field accessors for the message type. /// </summary>
/// </summary> public ReadOnlyCollection<IFieldAccessor> Accessors { get { return accessors; } }
public ReadOnlyCollection<IFieldAccessor> Accessors { get { return accessors; } }
public ReadOnlyCollection<OneofAccessor> Oneofs { get { return oneofs; } }
public ReadOnlyCollection<OneofAccessor> Oneofs { get { return oneofs; } }
// TODO: Review this, as it's easy to get confused between FieldNumber and Index.
// TODO: Review this, as it's easy to get confused between FieldNumber and Index. // Currently only used to get an accessor related to a oneof... maybe just make that simpler?
// Currently only used to get an accessor related to a oneof... maybe just make that simpler? public IFieldAccessor this[int fieldNumber]
public IFieldAccessor this[int fieldNumber] {
{ get
get {
{ FieldDescriptor field = descriptor.FindFieldByNumber(fieldNumber);
FieldDescriptor field = descriptor.FindFieldByNumber(fieldNumber); return accessors[field.Index];
return accessors[field.Index]; }
} }
} }
}
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Enumeration of all the possible field types. The odd formatting is to make it very clear /// Enumeration of all the possible field types. The odd formatting is to make it very clear
/// which attribute applies to which value, while maintaining a compact format. /// which attribute applies to which value, while maintaining a compact format.
/// </summary> /// </summary>
public enum FieldType public enum FieldType
{ {
Double, Double,
Float, Float,
Int64, Int64,
UInt64, UInt64,
Int32, Int32,
Fixed64, Fixed64,
Fixed32, Fixed32,
Bool, Bool,
String, String,
Group, Group,
Message, Message,
Bytes, Bytes,
UInt32, UInt32,
SFixed32, SFixed32,
SFixed64, SFixed64,
SInt32, SInt32,
SInt64, SInt64,
Enum Enum
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Interface implemented by all descriptor types. /// Interface implemented by all descriptor types.
/// </summary> /// </summary>
public interface IDescriptor public interface IDescriptor
{ {
string Name { get; } string Name { get; }
string FullName { get; } string FullName { get; }
FileDescriptor File { get; } FileDescriptor File { get; }
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.Descriptors; namespace Google.Protobuf.Reflection
{
namespace Google.Protobuf.FieldAccess /// <summary>
{ /// Allows fields to be reflectively accessed.
/// <summary> /// </summary>
/// Allows fields to be reflectively accessed. public interface IFieldAccessor
/// </summary> {
public interface IFieldAccessor /// <summary>
{ /// Returns the descriptor associated with this field.
/// <summary> /// </summary>
/// Returns the descriptor associated with this field. FieldDescriptor Descriptor { get; }
/// </summary>
FieldDescriptor Descriptor { get; } // TODO: Should the argument type for these messages by IReflectedMessage?
// TODO: Should the argument type for these messages by IReflectedMessage? /// <summary>
/// Clears the field in the specified message. (For repeated fields,
/// <summary> /// this clears the list.)
/// Clears the field in the specified message. (For repeated fields, /// </summary>
/// this clears the list.) void Clear(object message);
/// </summary>
void Clear(object message); /// <summary>
/// Fetches the field value. For repeated values, this will be an
/// <summary> /// <see cref="IList"/> implementation. For map values, this will be an
/// Fetches the field value. For repeated values, this will be an /// <see cref="IDictionary"/> implementation.
/// <see cref="IList"/> implementation. For map values, this will be an /// </summary>
/// <see cref="IDictionary"/> implementation. object GetValue(object message);
/// </summary>
object GetValue(object message); /// <summary>
/// Mutator for single "simple" fields only.
/// <summary> /// </summary>
/// Mutator for single "simple" fields only. /// <remarks>
/// </summary> /// Repeated fields are mutated by fetching the value and manipulating it as a list.
/// <remarks> /// Map fields are mutated by fetching the value and manipulating it as a dictionary.
/// Repeated fields are mutated by fetching the value and manipulating it as a list. /// </remarks>
/// Map fields are mutated by fetching the value and manipulating it as a dictionary. /// <exception cref="InvalidOperationException">The field is not a "simple" field, or the message is frozen.</exception>
/// </remarks> void SetValue(object message, object value);
/// <exception cref="InvalidOperationException">The field is not a "simple" field, or the message is frozen.</exception> }
void SetValue(object message, object value);
}
} }
\ No newline at end of file
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
using System; using System;
using System.Collections; using System.Collections;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf.FieldAccess namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Accessor for map fields. /// Accessor for map fields.
......
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.DescriptorProtos; using Google.Protobuf.DescriptorProtos;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Describes a single method in a service. /// Describes a single method in a service.
/// </summary> /// </summary>
public sealed class MethodDescriptor : DescriptorBase public sealed class MethodDescriptor : DescriptorBase
{ {
private readonly MethodDescriptorProto proto; private readonly MethodDescriptorProto proto;
private readonly ServiceDescriptor service; private readonly ServiceDescriptor service;
private MessageDescriptor inputType; private MessageDescriptor inputType;
private MessageDescriptor outputType; private MessageDescriptor outputType;
/// <value> /// <value>
/// The service this method belongs to. /// The service this method belongs to.
/// </value> /// </value>
public ServiceDescriptor Service { get { return service; } } public ServiceDescriptor Service { get { return service; } }
/// <value> /// <value>
/// The method's input type. /// The method's input type.
/// </value> /// </value>
public MessageDescriptor InputType { get { return inputType; } } public MessageDescriptor InputType { get { return inputType; } }
/// <value> /// <value>
/// The method's input type. /// The method's input type.
/// </value> /// </value>
public MessageDescriptor OutputType { get { return outputType; } } public MessageDescriptor OutputType { get { return outputType; } }
internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file, internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
ServiceDescriptor parent, int index) ServiceDescriptor parent, int index)
: base(file, parent.FullName + "." + proto.Name, index) : base(file, parent.FullName + "." + proto.Name, index)
{ {
this.proto = proto; this.proto = proto;
service = parent; service = parent;
file.DescriptorPool.AddSymbol(this); file.DescriptorPool.AddSymbol(this);
} }
internal MethodDescriptorProto Proto { get { return proto; } } internal MethodDescriptorProto Proto { get { return proto; } }
/// <summary> /// <summary>
/// The brief name of the descriptor's target. /// The brief name of the descriptor's target.
/// </summary> /// </summary>
public override string Name { get { return proto.Name; } } public override string Name { get { return proto.Name; } }
internal void CrossLink() internal void CrossLink()
{ {
IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this); IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
if (!(lookup is MessageDescriptor)) if (!(lookup is MessageDescriptor))
{ {
throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type."); throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
} }
inputType = (MessageDescriptor) lookup; inputType = (MessageDescriptor) lookup;
lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this); lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
if (!(lookup is MessageDescriptor)) if (!(lookup is MessageDescriptor))
{ {
throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type."); throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
} }
outputType = (MessageDescriptor) lookup; outputType = (MessageDescriptor) lookup;
} }
} }
} }
\ No newline at end of file
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2015 Google Inc. All rights reserved. // Copyright 2015 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using Google.Protobuf.Descriptors; using System;
using System; using System.Reflection;
using System.Reflection;
namespace Google.Protobuf.Reflection
namespace Google.Protobuf.FieldAccess {
{ /// <summary>
/// <summary> /// Reflection access for a oneof, allowing clear and "get case" actions.
/// Reflection access for a oneof, allowing clear and "get case" actions. /// </summary>
/// </summary> public sealed class OneofAccessor
public sealed class OneofAccessor {
{ private readonly Func<object, int> caseDelegate;
private readonly Func<object, int> caseDelegate; private readonly Action<object> clearDelegate;
private readonly Action<object> clearDelegate; private OneofDescriptor descriptor;
private OneofDescriptor descriptor;
internal OneofAccessor(Type type, string propertyName, OneofDescriptor descriptor)
internal OneofAccessor(Type type, string propertyName, OneofDescriptor descriptor) {
{ PropertyInfo property = type.GetProperty(propertyName + "Case");
PropertyInfo property = type.GetProperty(propertyName + "Case"); if (property == null || !property.CanRead)
if (property == null || !property.CanRead) {
{ throw new ArgumentException("Not all required properties/methods available");
throw new ArgumentException("Not all required properties/methods available"); }
} this.descriptor = descriptor;
this.descriptor = descriptor; caseDelegate = ReflectionUtil.CreateFuncObjectT<int>(property.GetGetMethod());
caseDelegate = ReflectionUtil.CreateFuncObjectT<int>(property.GetGetMethod());
this.descriptor = descriptor;
this.descriptor = descriptor; MethodInfo clearMethod = type.GetMethod("Clear" + propertyName);
MethodInfo clearMethod = type.GetMethod("Clear" + propertyName); clearDelegate = ReflectionUtil.CreateActionObject(clearMethod);
clearDelegate = ReflectionUtil.CreateActionObject(clearMethod); }
}
public OneofDescriptor Descriptor { get { return descriptor; } }
public OneofDescriptor Descriptor { get { return descriptor; } }
/// <summary>
/// <summary> /// Clears the oneof in the specified message.
/// Clears the oneof in the specified message. /// </summary>
/// </summary> public void Clear(object message)
public void Clear(object message) {
{ clearDelegate(message);
clearDelegate(message); }
}
/// <summary>
/// <summary> /// Indicates which field in the oneof is set for specified message
/// Indicates which field in the oneof is set for specified message /// </summary>
/// </summary> public FieldDescriptor GetCaseFieldDescriptor(object message)
public FieldDescriptor GetCaseFieldDescriptor(object message) {
{ int fieldNumber = caseDelegate(message);
int fieldNumber = caseDelegate(message); if (fieldNumber > 0)
if (fieldNumber > 0) {
{ return descriptor.ContainingType.FindFieldByNumber(fieldNumber);
return descriptor.ContainingType.FindFieldByNumber(fieldNumber); }
} return null;
return null; }
} }
} }
}
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2015 Google Inc. All rights reserved. // Copyright 2015 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Google.Protobuf.DescriptorProtos; using Google.Protobuf.DescriptorProtos;
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
public sealed class OneofDescriptor : DescriptorBase public sealed class OneofDescriptor : DescriptorBase
{ {
private readonly OneofDescriptorProto proto; private readonly OneofDescriptorProto proto;
private MessageDescriptor containingType; private MessageDescriptor containingType;
private IList<FieldDescriptor> fields; private IList<FieldDescriptor> fields;
internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index) internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index)
: base(file, file.ComputeFullName(parent, proto.Name), index) : base(file, file.ComputeFullName(parent, proto.Name), index)
{ {
this.proto = proto; this.proto = proto;
containingType = parent; containingType = parent;
file.DescriptorPool.AddSymbol(this); file.DescriptorPool.AddSymbol(this);
} }
/// <summary> /// <summary>
/// The brief name of the descriptor's target. /// The brief name of the descriptor's target.
/// </summary> /// </summary>
public override string Name { get { return proto.Name; } } public override string Name { get { return proto.Name; } }
public MessageDescriptor ContainingType public MessageDescriptor ContainingType
{ {
get { return containingType; } get { return containingType; }
} }
public IList<FieldDescriptor> Fields { get { return fields; } } public IList<FieldDescriptor> Fields { get { return fields; } }
internal void CrossLink() internal void CrossLink()
{ {
List<FieldDescriptor> fieldCollection = new List<FieldDescriptor>(); List<FieldDescriptor> fieldCollection = new List<FieldDescriptor>();
foreach (var field in ContainingType.Fields) foreach (var field in ContainingType.Fields)
{ {
if (field.ContainingOneof == this) if (field.ContainingOneof == this)
{ {
fieldCollection.Add(field); fieldCollection.Add(field);
} }
} }
fields = new ReadOnlyCollection<FieldDescriptor>(fieldCollection); fields = new ReadOnlyCollection<FieldDescriptor>(fieldCollection);
} }
} }
} }
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/ // https://developers.google.com/protocol-buffers/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
namespace Google.Protobuf.Descriptors namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Represents a package in the symbol table. We use PackageDescriptors /// Represents a package in the symbol table. We use PackageDescriptors
/// just as placeholders so that someone cannot define, say, a message type /// just as placeholders so that someone cannot define, say, a message type
/// that has the same name as an existing package. /// that has the same name as an existing package.
/// </summary> /// </summary>
internal sealed class PackageDescriptor : IDescriptor internal sealed class PackageDescriptor : IDescriptor
{ {
private readonly string name; private readonly string name;
private readonly string fullName; private readonly string fullName;
private readonly FileDescriptor file; private readonly FileDescriptor file;
internal PackageDescriptor(string name, string fullName, FileDescriptor file) internal PackageDescriptor(string name, string fullName, FileDescriptor file)
{ {
this.file = file; this.file = file;
this.fullName = fullName; this.fullName = fullName;
this.name = name; this.name = name;
} }
public string Name public string Name
{ {
get { return name; } get { return name; }
} }
public string FullName public string FullName
{ {
get { return fullName; } get { return fullName; }
} }
public FileDescriptor File public FileDescriptor File
{ {
get { return file; } get { return file; }
} }
} }
} }
\ No newline at end of file
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
using System; using System;
using System.Collections; using System.Collections;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf.FieldAccess namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Accessor for repeated fields. /// Accessor for repeated fields.
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
using System.Reflection; using System.Reflection;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf.FieldAccess namespace Google.Protobuf.Reflection
{ {
/// <summary> /// <summary>
/// Accessor for single fields. /// Accessor for single fields.
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#endregion #endregion
using System; using System;
using Google.Protobuf.Descriptors; using Google.Protobuf.Reflection;
namespace Google.Protobuf namespace Google.Protobuf
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment