aboutsummaryrefslogtreecommitdiff
path: root/csharp
diff options
context:
space:
mode:
authorJisi Liu <jisi.liu@gmail.com>2016-04-01 16:46:49 -0700
committerJisi Liu <jisi.liu@gmail.com>2016-04-01 16:46:49 -0700
commitcba75ad40431ca0825aa59df3c9265a12c0ae3b6 (patch)
treef7ce45e0922c46eecd01a36afb6d8ec5a71c8155 /csharp
parent89343d87c6a335be561fd17c8e40c72901d2f152 (diff)
parent452e2b2c5c607ab5d63cd813793f1aa960f19d1c (diff)
downloadprotobuf-cba75ad40431ca0825aa59df3c9265a12c0ae3b6.tar.gz
protobuf-cba75ad40431ca0825aa59df3c9265a12c0ae3b6.tar.bz2
protobuf-cba75ad40431ca0825aa59df3c9265a12c0ae3b6.zip
Merge branch 'master' of github.com:google/protobuf
Diffstat (limited to 'csharp')
-rw-r--r--csharp/Google.Protobuf.Tools.nuspec37
-rw-r--r--csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs1
-rw-r--r--csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs1
-rw-r--r--csharp/src/Google.Protobuf/Google.Protobuf.nuspec14
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs100
5 files changed, 76 insertions, 77 deletions
diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec
new file mode 100644
index 00000000..2b66b081
--- /dev/null
+++ b/csharp/Google.Protobuf.Tools.nuspec
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<package>
+ <metadata>
+ <id>Google.Protobuf.Tools</id>
+ <title>Google Protocol Buffers tools</title>
+ <summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
+ <description>See project site for more info.</description>
+ <version>3.0.0-beta2</version>
+ <authors>Google Inc.</authors>
+ <owners>protobuf-packages</owners>
+ <licenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</licenseUrl>
+ <projectUrl>https://github.com/google/protobuf</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <releaseNotes>Tools for Protocol Buffers</releaseNotes>
+ <copyright>Copyright 2015, Google Inc.</copyright>
+ <tags>Protocol Buffers Binary Serialization Format Google proto proto3</tags>
+ </metadata>
+ <files>
+ <file src="protoc\windows_x86\protoc.exe" target="tools\windows_x86\protoc.exe" />
+ <file src="protoc\windows_x64\protoc.exe" target="tools\windows_x64\protoc.exe" />
+ <file src="protoc\linux_x86\protoc" target="tools\linux_x86\protoc" />
+ <file src="protoc\linux_x64\protoc" target="tools\linux_x64\protoc" />
+ <file src="protoc\macosx_x86\protoc" target="tools\macosx_x86\protoc" />
+ <file src="protoc\macosx_x64\protoc" target="tools\macosx_x64\protoc" />
+ <file src="..\src\google\protobuf\any.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\api.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\descriptor.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\duration.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\empty.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\field_mask.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\source_context.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\struct.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\timestamp.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\type.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\wrappers.proto" target="tools\google\protobuf" />
+ </files>
+</package> \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
index 42455043..344d727b 100644
--- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
@@ -321,7 +321,6 @@ namespace Google.Protobuf
[TestCase("1970-01-01T00:00:00.001Z", 1000000)]
[TestCase("1970-01-01T00:00:00.010Z", 10000000)]
[TestCase("1970-01-01T00:00:00.100Z", 100000000)]
- [TestCase("1970-01-01T00:00:00.100Z", 100000000)]
[TestCase("1970-01-01T00:00:00.120Z", 120000000)]
[TestCase("1970-01-01T00:00:00.123Z", 123000000)]
[TestCase("1970-01-01T00:00:00.123400Z", 123400000)]
diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
index a0a62227..527ab336 100644
--- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
@@ -249,7 +249,6 @@ namespace Google.Protobuf
[TestCase("[,", 1)]
[TestCase("{", 1)]
[TestCase("{,", 1)]
- [TestCase("{", 1)]
[TestCase("{[", 1)]
[TestCase("{{", 1)]
[TestCase("{0", 1)]
diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec
index d5302544..f51bc89a 100644
--- a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec
+++ b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec
@@ -23,7 +23,6 @@
<group targetFramework="xamarin.ios" />
<group targetFramework="monotouch" />
<group targetFramework="monoandroid" />
-
<!-- Dependencies for newer, more granular platforms (.NET Core etc) -->
<group targetFramework="dotnet">
<dependency id="System.Collections" version="4.0.0" />
@@ -49,18 +48,5 @@
<file src="bin/ReleaseSigned/Google.Protobuf.pdb" target="lib/dotnet" />
<file src="bin/ReleaseSigned/Google.Protobuf.xml" target="lib/dotnet" />
<file src="**\*.cs" target="src" />
- <file src="..\..\..\cmake\Release\protoc.exe" target="tools" />
- <file src="..\..\..\src\google\protobuf\any.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\api.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\descriptor.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\duration.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\empty.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\field_mask.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\source_context.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\struct.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\timestamp.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\any.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\type.proto" target="tools\google\protobuf" />
- <file src="..\..\..\src\google\protobuf\wrappers.proto" target="tools\google\protobuf" />
</files>
</package> \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
index 6083f171..de6e5717 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -30,9 +30,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
-using System;
-using System.Linq;
using Google.Protobuf.Compatibility;
+using System;
namespace Google.Protobuf.Reflection
{
@@ -41,20 +40,35 @@ namespace Google.Protobuf.Reflection
/// </summary>
public sealed class FieldDescriptor : DescriptorBase, IComparable<FieldDescriptor>
{
- private readonly FieldDescriptorProto proto;
private EnumDescriptor enumType;
private MessageDescriptor messageType;
- private readonly MessageDescriptor containingType;
- private readonly OneofDescriptor containingOneof;
private FieldType fieldType;
private readonly string propertyName; // Annoyingly, needed in Crosslink.
private IFieldAccessor accessor;
+ /// <summary>
+ /// Get the field's containing message type.
+ /// </summary>
+ public MessageDescriptor ContainingType { get; }
+
+ /// <summary>
+ /// Returns the oneof containing this field, or <c>null</c> if it is not part of a oneof.
+ /// </summary>
+ public OneofDescriptor ContainingOneof { get; }
+
+ /// <summary>
+ /// The effective JSON name for this field. This is usually the lower-camel-cased form of the field name,
+ /// but can be overridden using the <c>json_name</c> option in the .proto file.
+ /// </summary>
+ public string JsonName { get; }
+
+ internal FieldDescriptorProto Proto { get; }
+
internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
MessageDescriptor parent, int index, string propertyName)
: base(file, file.ComputeFullName(parent, proto.Name), index)
{
- this.proto = proto;
+ Proto = proto;
if (proto.Type != 0)
{
fieldType = GetFieldTypeFromProtoType(proto.Type);
@@ -64,7 +78,7 @@ namespace Google.Protobuf.Reflection
{
throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
}
- containingType = parent;
+ ContainingType = parent;
// OneofIndex "defaults" to -1 due to a hack in FieldDescriptor.OnConstruction.
if (proto.OneofIndex != -1)
{
@@ -73,7 +87,7 @@ namespace Google.Protobuf.Reflection
throw new DescriptorValidationException(this,
$"FieldDescriptorProto.oneof_index is out of range for type {parent.Name}");
}
- containingOneof = parent.Oneofs[proto.OneofIndex];
+ ContainingOneof = parent.Oneofs[proto.OneofIndex];
}
file.DescriptorPool.AddSymbol(this);
@@ -83,20 +97,14 @@ namespace Google.Protobuf.Reflection
// We could trust the generated code and check whether the type of the property is
// a MapField, but that feels a tad nasty.
this.propertyName = propertyName;
+ JsonName = Proto.JsonName == "" ? JsonFormatter.ToCamelCase(Proto.Name) : Proto.JsonName;
}
+
/// <summary>
/// The brief name of the descriptor's target.
/// </summary>
- public override string Name { get { return proto.Name; } }
-
-
- /// <summary>
- /// The json_name option of the descriptor's target.
- /// </summary>
- public string JsonName { get { return proto.JsonName == "" ? JsonFormatter.ToCamelCase(proto.Name) : proto.JsonName; } }
-
- internal FieldDescriptorProto Proto { get { return proto; } }
+ public override string Name => Proto.Name;
/// <summary>
/// Returns the accessor for this field.
@@ -116,7 +124,7 @@ namespace Google.Protobuf.Reflection
/// and this property will return null.
/// </para>
/// </remarks>
- public IFieldAccessor Accessor { get { return accessor; } }
+ public IFieldAccessor Accessor => accessor;
/// <summary>
/// Maps a field type as included in the .proto file to a FieldType.
@@ -169,62 +177,32 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// Returns <c>true</c> if this field is a repeated field; <c>false</c> otherwise.
/// </summary>
- public bool IsRepeated
- {
- get { return Proto.Label == FieldDescriptorProto.Types.Label.LABEL_REPEATED; }
- }
+ public bool IsRepeated => Proto.Label == FieldDescriptorProto.Types.Label.LABEL_REPEATED;
/// <summary>
/// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
/// </summary>
- public bool IsMap
- {
- get { return fieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry; }
- }
+ public bool IsMap => fieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry;
/// <summary>
/// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
/// </summary>
- public bool IsPacked
- {
+ public bool IsPacked =>
// Note the || rather than && here - we're effectively defaulting to packed, because that *is*
// the default in proto3, which is all we support. We may give the wrong result for the protos
// within descriptor.proto, but that's okay, as they're never exposed and we don't use IsPacked
// within the runtime.
- get { return Proto.Options == null || Proto.Options.Packed; }
- }
-
- /// <summary>
- /// Get the field's containing message type.
- /// </summary>
- public MessageDescriptor ContainingType
- {
- get { return containingType; }
- }
-
- /// <summary>
- /// Returns the oneof containing this field, or <c>null</c> if it is not part of a oneof.
- /// </summary>
- public OneofDescriptor ContainingOneof
- {
- get { return containingOneof; }
- }
-
+ Proto.Options == null || Proto.Options.Packed;
+
/// <summary>
/// Returns the type of the field.
/// </summary>
- public FieldType FieldType
- {
- get { return fieldType; }
- }
+ public FieldType FieldType => fieldType;
/// <summary>
/// Returns the field number declared in the proto file.
/// </summary>
- public int FieldNumber
- {
- get { return Proto.Number; }
- }
+ public int FieldNumber => Proto.Number;
/// <summary>
/// Compares this descriptor with another one, ordering in "canonical" order
@@ -234,7 +212,7 @@ namespace Google.Protobuf.Reflection
/// </summary>
public int CompareTo(FieldDescriptor other)
{
- if (other.containingType != containingType)
+ if (other.ContainingType != ContainingType)
{
throw new ArgumentException("FieldDescriptors can only be compared to other FieldDescriptors " +
"for fields of the same message type.");
@@ -337,14 +315,14 @@ namespace Google.Protobuf.Reflection
File.DescriptorPool.AddFieldByNumber(this);
- if (containingType != null && containingType.Proto.Options != null && containingType.Proto.Options.MessageSetWireFormat)
+ if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat)
{
throw new DescriptorValidationException(this, "MessageSet format is not supported.");
}
- accessor = CreateAccessor(propertyName);
+ accessor = CreateAccessor();
}
- private IFieldAccessor CreateAccessor(string propertyName)
+ private IFieldAccessor CreateAccessor()
{
// If we're given no property name, that's because we really don't want an accessor.
// (At the moment, that means it's a map entry message...)
@@ -352,10 +330,10 @@ namespace Google.Protobuf.Reflection
{
return null;
}
- var property = containingType.ClrType.GetProperty(propertyName);
+ var property = ContainingType.ClrType.GetProperty(propertyName);
if (property == null)
{
- throw new DescriptorValidationException(this, $"Property {propertyName} not found in {containingType.ClrType}");
+ throw new DescriptorValidationException(this, $"Property {propertyName} not found in {ContainingType.ClrType}");
}
return IsMap ? new MapFieldAccessor(property, this)
: IsRepeated ? new RepeatedFieldAccessor(property, this)