Commit fb607d6f authored by csharptest's avatar csharptest Committed by rogerk

Merged local fix for Issue 50

parents eb6476d7 2be3870a
=============================================================================== ===============================================================================
Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet
(skeet@pobox.com) based on the work of many talented people. (skeet@pobox.com) based on the work of many talented people.
For more information about this port, visit its homepage: For more information about this port, visit its homepage:
http://protobuf-csharp-port.googlecode.com http://protobuf-csharp-port.googlecode.com
For more information about Protocol Buffers in general, visit the project page For more information about Protocol Buffers in general, visit the project page
for the C++, Java and Python project: for the C++, Java and Python project:
http://protobuf.googlecode.com http://protobuf.googlecode.com
=============================================================================== ===============================================================================
RELEASE NOTES - Version 2.4.1.TBD RELEASE NOTES - Version 2.4.1.473
=============================================================================== ===============================================================================
Features: Features:
- Added option service_generator_type to control service generation with - Added option service_generator_type to control service generation with
NONE, GENERIC, INTERFACE, or IRPCDISPATCH NONE, GENERIC, INTERFACE, or IRPCDISPATCH
- Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking - Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking
services and implementations. services and implementations.
- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the - Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the
location of protoc.exe. location of protoc.exe.
- Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow - Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow
custom implementation of writers with both speed and size optimizations. custom implementation of writers with both speed and size optimizations.
- Addition of the "Google.ProtoBuffers.Serialization" assembly to support - Addition of the "Google.ProtoBuffers.Serialization" assembly to support
reading and writing messages to/from XML, JSON, IDictionary<,> and others. reading and writing messages to/from XML, JSON, IDictionary<,> and others.
- Several performance related fixes and tweeks - Several performance related fixes and tweeks
- Issue 3: Add option to mark generated code with attribute - Issue 3: Add option to mark generated code with attribute
- Issue 20: Support for decorating classes [Serializable] - Issue 20: Support for decorating classes [Serializable]
- Issue 21: Decorate fields with [deprecated=true] as [System.Obsolete] - Issue 21: Decorate fields with [deprecated=true] as [System.Obsolete]
- Issue 22: Reusable Builder classes - Issue 22: Reusable Builder classes
- Issue 24: Support for using Json/Xml formats with ICodedInputStream - Issue 24: Support for using Json/Xml formats with ICodedInputStream
- Issue 25: Added support for NuGet packages - Issue 25: Added support for NuGet packages
- Issue 31: Upgraded protoc.exe and descriptor to 2.4.1 - Issue 31: Upgraded protoc.exe and descriptor to 2.4.1
Fixes: Fixes:
- Issue 13: Message with Field same name as message causes uncompilable .cs - Issue 13: Message with Field same name as message causes uncompilable .cs
- Issue 16: Does not integrate well with other tooling - Issue 16: Does not integrate well with other tooling
- Issue 19: Support for negative enum values - Issue 19: Support for negative enum values
- Issue 26: AddRange in GeneratedBuilder iterates twice. - Issue 26: AddRange in GeneratedBuilder iterates twice.
- Issue 27: Remove XML documentation output from test projects to clear - Issue 27: Remove XML documentation output from test projects to clear
warnings/errors. warnings/errors.
- Issue 28: Circular message dependencies result in null default values for - Issue 28: Circular message dependencies result in null default values for
Message fields. Message fields.
- Issue 29: Message classes generated have a public default constructor. You - Issue 29: Message classes generated have a public default constructor. You
can disable private ctor generation with the option generate_private_ctor. can disable private ctor generation with the option generate_private_ctor.
- Issue 35: Fixed a bug in ProtoGen handling of arguments with trailing \ - Issue 35: Fixed a bug in ProtoGen handling of arguments with trailing \
- Big-endian support for float, and double on Silverlight - Big-endian support for float, and double on Silverlight
- Packed and Unpacked parsing allow for all repeated, as per version 2.3 - Packed and Unpacked parsing allow for all repeated, as per version 2.3
- Fix for leaving Builder a public ctor on internal classes for use with - Fix for leaving Builder a public ctor on internal classes for use with
generic "where T: new()" constraints. generic "where T: new()" constraints.
Other: Other:
- Changed the code signing key to a privately held key - Changed the code signing key to a privately held key
- Reformatted all code and line-endings to C# defaults - Reformatted all code and line-endings to C# defaults
- Reworking of performance benchmarks to produce reliable results, option /v2 - Reworking of performance benchmarks to produce reliable results, option /v2
- Issue 34: Silverlight assemblies are now unit tested - Issue 34: Silverlight assemblies are now unit tested
=============================================================================== ===============================================================================
RELEASE NOTES - Version 2.3.0.277 RELEASE NOTES - Version 2.3.0.277
=============================================================================== ===============================================================================
Features: Features:
- Added cls_compliance option to generate attributes indicating - Added cls_compliance option to generate attributes indicating
non-CLS-compliance. non-CLS-compliance.
- Added file_extension option to control the generated output file's extension. - Added file_extension option to control the generated output file's extension.
- Added umbrella_namespace option to place the umbrella class into a nested - Added umbrella_namespace option to place the umbrella class into a nested
namespace to address issues with proto files having the same name as a namespace to address issues with proto files having the same name as a
message it contains. message it contains.
- Added output_directory option to set the output path for the source file(s). - Added output_directory option to set the output path for the source file(s).
- Added ignore_google_protobuf option to avoid generating code for includes - Added ignore_google_protobuf option to avoid generating code for includes
from the google.protobuf package. from the google.protobuf package.
- Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to - Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to
generate code with "option optimize_for = LITE_RUNTIME;". generate code with "option optimize_for = LITE_RUNTIME;".
- Added ability to invoke protoc.exe from within ProtoGen.exe. - Added ability to invoke protoc.exe from within ProtoGen.exe.
- Upgraded to protoc.exe (2.3) compiler. - Upgraded to protoc.exe (2.3) compiler.
Fixes: Fixes:
- Issue 9: Class cannot be static and sealed error - Issue 9: Class cannot be static and sealed error
- Issue 12: default value for enumerate fields must be filled out - Issue 12: default value for enumerate fields must be filled out
Other: Other:
- Rewrite of build using MSBbuild instead of NAnt - Rewrite of build using MSBbuild instead of NAnt
- Moved to NUnit Version 2.2.8.0 - Moved to NUnit Version 2.2.8.0
- Changed to using secure .snk for releases - Changed to using secure .snk for releases
=============================================================================== ===============================================================================
RELEASE NOTES - Version 0.9.1 RELEASE NOTES - Version 0.9.1
=============================================================================== ===============================================================================
Fixes: Fixes:
- issue 10: Incorrect encoding of packed fields when serialized - issue 10: Incorrect encoding of packed fields when serialized
=============================================================================== ===============================================================================
RELEASE NOTES - Version 0.9.0 RELEASE NOTES - Version 0.9.0
=============================================================================== ===============================================================================
- Initial release - Initial release
=============================================================================== ===============================================================================
\ No newline at end of file
...@@ -129,4 +129,9 @@ message DeprecatedFieldsMessage { ...@@ -129,4 +129,9 @@ message DeprecatedFieldsMessage {
optional DeprecatedEnum EnumValue = 5 [deprecated = true]; optional DeprecatedEnum EnumValue = 5 [deprecated = true];
repeated DeprecatedEnum EnumArray = 6 [deprecated = true]; repeated DeprecatedEnum EnumArray = 6 [deprecated = true];
} }
\ No newline at end of file
// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
message ItemField {
optional int32 item = 1;
}
...@@ -112,7 +112,7 @@ message MyMessage { ...@@ -112,7 +112,7 @@ message MyMessage {
args.Add(String.Format(@"""/out:{0}""", tempDll.TempPath)); args.Add(String.Format(@"""/out:{0}""", tempDll.TempPath));
args.Add("/r:System.dll"); args.Add("/r:System.dll");
args.Add(String.Format(@"""/r:{0}""", args.Add(String.Format(@"""/r:{0}""",
typeof (Google.ProtocolBuffers.DescriptorProtos.DescriptorProto).Assembly. typeof(Google.ProtocolBuffers.DescriptorProtos.DescriptorProto).Assembly.
Location)); Location));
args.AddRange(sources); args.AddRange(sources);
...@@ -162,7 +162,7 @@ message MyMessage { ...@@ -162,7 +162,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -188,7 +188,7 @@ message " + ...@@ -188,7 +188,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple." + test, true, true); Type t = a.GetType("nunit.simple." + test, true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple.Proto." + test, true, true); a.GetType("nunit.simple.Proto." + test, true, true);
} }
...@@ -206,7 +206,7 @@ message " + ...@@ -206,7 +206,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("MyNewNamespace.MyMessage", true, true); Type t = a.GetType("MyNewNamespace.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("MyNewNamespace." + test, true, true); a.GetType("MyNewNamespace." + test, true, true);
} }
...@@ -224,7 +224,7 @@ message " + ...@@ -224,7 +224,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple.MyUmbrellaClassname", true, true); a.GetType("nunit.simple.MyUmbrellaClassname", true, true);
} }
...@@ -242,7 +242,7 @@ message " + ...@@ -242,7 +242,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple." + test + "+MyMessage", true, true); Type t = a.GetType("nunit.simple." + test + "+MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -260,7 +260,7 @@ message " + ...@@ -260,7 +260,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -290,7 +290,7 @@ message MyMessage { ...@@ -290,7 +290,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath, "/warnaserror+"); Assembly a = RunCsc(0, source.TempPath, "/warnaserror+");
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -308,7 +308,7 @@ message MyMessage { ...@@ -308,7 +308,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -326,7 +326,7 @@ message MyMessage { ...@@ -326,7 +326,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple.MyUmbrella.Namespace." + test, true, true); a.GetType("nunit.simple.MyUmbrella.Namespace." + test, true, true);
} }
...@@ -344,7 +344,7 @@ message MyMessage { ...@@ -344,7 +344,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple." + test + "+MyMessage", true, true); Type t = a.GetType("nunit.simple." + test + "+MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -387,7 +387,7 @@ message " + ...@@ -387,7 +387,7 @@ message " +
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -421,7 +421,7 @@ option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace""; ...@@ -421,7 +421,7 @@ option (google.protobuf.csharp_file_options).namespace = ""MyNewNamespace"";
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("MyNewNamespace.MyMessage", true, true); Type t = a.GetType("MyNewNamespace.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("MyNewNamespace." + test, true, true); a.GetType("MyNewNamespace." + test, true, true);
} }
...@@ -493,7 +493,7 @@ message MyMessage { ...@@ -493,7 +493,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("MyNewNamespace.MyMessage", true, true); Type t = a.GetType("MyNewNamespace.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("MyNewNamespace." + test, true, true); a.GetType("MyNewNamespace." + test, true, true);
} }
...@@ -532,7 +532,7 @@ message MyMessage { ...@@ -532,7 +532,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("MyNewNamespace.MyMessage", true, true); Type t = a.GetType("MyNewNamespace.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("MyNewNamespace." + test, true, true); a.GetType("MyNewNamespace." + test, true, true);
} }
...@@ -560,7 +560,7 @@ message MyMessage { ...@@ -560,7 +560,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -580,7 +580,7 @@ message MyMessage { ...@@ -580,7 +580,7 @@ message MyMessage {
Assembly a = RunCsc(0, source.TempPath); Assembly a = RunCsc(0, source.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t = a.GetType("nunit.simple.MyMessage", true, true); Type t = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple." + test, true, true); a.GetType("nunit.simple." + test, true, true);
} }
...@@ -620,10 +620,10 @@ message MyMessageList { ...@@ -620,10 +620,10 @@ message MyMessageList {
Assembly a = RunCsc(0, source1.TempPath, source2.TempPath); Assembly a = RunCsc(0, source1.TempPath, source2.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t1 = a.GetType("nunit.simple.MyMessage", true, true); Type t1 = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t1), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t1), "Expect an IMessage");
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t2 = a.GetType("nunit.simple.MyMessageList", true, true); Type t2 = a.GetType("nunit.simple.MyMessageList", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t2), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t2), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple.Proto.MyMessage", true, true); a.GetType("nunit.simple.Proto.MyMessage", true, true);
a.GetType("nunit.simple.Proto.MyMessageList", true, true); a.GetType("nunit.simple.Proto.MyMessageList", true, true);
...@@ -664,10 +664,10 @@ message MyMessageList { ...@@ -664,10 +664,10 @@ message MyMessageList {
Assembly a = RunCsc(0, source1.TempPath, source2.TempPath); Assembly a = RunCsc(0, source1.TempPath, source2.TempPath);
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t1 = a.GetType("nunit.simple.MyMessage", true, true); Type t1 = a.GetType("nunit.simple.MyMessage", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t1), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t1), "Expect an IMessage");
//assert that the message type is in the expected namespace //assert that the message type is in the expected namespace
Type t2 = a.GetType("nunit.simple.MyMessageList", true, true); Type t2 = a.GetType("nunit.simple.MyMessageList", true, true);
Assert.IsTrue(typeof (IMessage).IsAssignableFrom(t2), "Expect an IMessage"); Assert.IsTrue(typeof(IMessage).IsAssignableFrom(t2), "Expect an IMessage");
//assert that we can find the static descriptor type //assert that we can find the static descriptor type
a.GetType("nunit.simple.Proto.MyMessage", true, true); a.GetType("nunit.simple.Proto.MyMessage", true, true);
a.GetType("nunit.simple.Proto.MyMessageList", true, true); a.GetType("nunit.simple.Proto.MyMessageList", true, true);
......
...@@ -47,12 +47,12 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -47,12 +47,12 @@ namespace Google.ProtocolBuffers.ProtoGen
private static readonly Dictionary<Type, Func<IDescriptor, ISourceGenerator>> GeneratorFactories = private static readonly Dictionary<Type, Func<IDescriptor, ISourceGenerator>> GeneratorFactories =
new Dictionary<Type, Func<IDescriptor, ISourceGenerator>> new Dictionary<Type, Func<IDescriptor, ISourceGenerator>>
{ {
{typeof (FileDescriptor), descriptor => new UmbrellaClassGenerator((FileDescriptor) descriptor)}, {typeof(FileDescriptor), descriptor => new UmbrellaClassGenerator((FileDescriptor) descriptor)},
{typeof (EnumDescriptor), descriptor => new EnumGenerator((EnumDescriptor) descriptor)}, {typeof(EnumDescriptor), descriptor => new EnumGenerator((EnumDescriptor) descriptor)},
{typeof (ServiceDescriptor), descriptor => new ServiceGenerator((ServiceDescriptor) descriptor)}, {typeof(ServiceDescriptor), descriptor => new ServiceGenerator((ServiceDescriptor) descriptor)},
{typeof (MessageDescriptor), descriptor => new MessageGenerator((MessageDescriptor) descriptor)}, {typeof(MessageDescriptor), descriptor => new MessageGenerator((MessageDescriptor) descriptor)},
// For other fields, we have IFieldSourceGenerators. // For other fields, we have IFieldSourceGenerators.
{typeof (FieldDescriptor), descriptor => new ExtensionGenerator((FieldDescriptor) descriptor)} {typeof(FieldDescriptor), descriptor => new ExtensionGenerator((FieldDescriptor) descriptor)}
}; };
public static IFieldSourceGenerator CreateFieldGenerator(FieldDescriptor field, int fieldOrdinal) public static IFieldSourceGenerator CreateFieldGenerator(FieldDescriptor field, int fieldOrdinal)
...@@ -77,9 +77,9 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -77,9 +77,9 @@ namespace Google.ProtocolBuffers.ProtoGen
public static ISourceGenerator CreateGenerator<T>(T descriptor) where T : IDescriptor public static ISourceGenerator CreateGenerator<T>(T descriptor) where T : IDescriptor
{ {
Func<IDescriptor, ISourceGenerator> factory; Func<IDescriptor, ISourceGenerator> factory;
if (!GeneratorFactories.TryGetValue(typeof (T), out factory)) if (!GeneratorFactories.TryGetValue(typeof(T), out factory))
{ {
throw new ArgumentException("No generator registered for " + typeof (T).Name); throw new ArgumentException("No generator registered for " + typeof(T).Name);
} }
return factory(descriptor); return factory(descriptor);
} }
......
...@@ -468,7 +468,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -468,7 +468,7 @@ namespace Google.ProtocolBuffers.Serialization
rawValue = null; rawValue = null;
if (ReadEnum(ref rawValue)) if (ReadEnum(ref rawValue))
{ {
if (Enum.IsDefined(typeof (T), rawValue)) if (Enum.IsDefined(typeof(T), rawValue))
{ {
if (rawValue is int) if (rawValue is int)
{ {
...@@ -476,7 +476,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -476,7 +476,7 @@ namespace Google.ProtocolBuffers.Serialization
} }
else if (rawValue is string) else if (rawValue is string)
{ {
value = (T) Enum.Parse(typeof (T), (string) rawValue, false); value = (T) Enum.Parse(typeof(T), (string) rawValue, false);
} }
else else
{ {
...@@ -565,7 +565,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -565,7 +565,7 @@ namespace Google.ProtocolBuffers.Serialization
} }
else if (rawValue is string) else if (rawValue is string)
{ {
list.Add((T) Enum.Parse(typeof (T), (string) rawValue, false)); list.Add((T) Enum.Parse(typeof(T), (string) rawValue, false));
} }
else else
{ {
......
...@@ -23,7 +23,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -23,7 +23,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref string value) protected override bool Read(ref string value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (string))) if (ReadAsText(ref text, typeof(string)))
{ {
value = text; value = text;
return true; return true;
...@@ -37,7 +37,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -37,7 +37,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref bool value) protected override bool Read(ref bool value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (bool))) if (ReadAsText(ref text, typeof(bool)))
{ {
value = XmlConvert.ToBoolean(text); value = XmlConvert.ToBoolean(text);
return true; return true;
...@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -51,7 +51,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref int value) protected override bool Read(ref int value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (int))) if (ReadAsText(ref text, typeof(int)))
{ {
value = XmlConvert.ToInt32(text); value = XmlConvert.ToInt32(text);
return true; return true;
...@@ -66,7 +66,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -66,7 +66,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref uint value) protected override bool Read(ref uint value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (uint))) if (ReadAsText(ref text, typeof(uint)))
{ {
value = XmlConvert.ToUInt32(text); value = XmlConvert.ToUInt32(text);
return true; return true;
...@@ -80,7 +80,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -80,7 +80,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref long value) protected override bool Read(ref long value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (long))) if (ReadAsText(ref text, typeof(long)))
{ {
value = XmlConvert.ToInt64(text); value = XmlConvert.ToInt64(text);
return true; return true;
...@@ -95,7 +95,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -95,7 +95,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref ulong value) protected override bool Read(ref ulong value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (ulong))) if (ReadAsText(ref text, typeof(ulong)))
{ {
value = XmlConvert.ToUInt64(text); value = XmlConvert.ToUInt64(text);
return true; return true;
...@@ -109,7 +109,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -109,7 +109,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref float value) protected override bool Read(ref float value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (float))) if (ReadAsText(ref text, typeof(float)))
{ {
value = XmlConvert.ToSingle(text); value = XmlConvert.ToSingle(text);
return true; return true;
...@@ -123,7 +123,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -123,7 +123,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref double value) protected override bool Read(ref double value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (double))) if (ReadAsText(ref text, typeof(double)))
{ {
value = XmlConvert.ToDouble(text); value = XmlConvert.ToDouble(text);
return true; return true;
...@@ -145,7 +145,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -145,7 +145,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool Read(ref ByteString value) protected override bool Read(ref ByteString value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (ByteString))) if (ReadAsText(ref text, typeof(ByteString)))
{ {
value = DecodeBytes(text); value = DecodeBytes(text);
return true; return true;
...@@ -160,7 +160,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -160,7 +160,7 @@ namespace Google.ProtocolBuffers.Serialization
protected override bool ReadEnum(ref object value) protected override bool ReadEnum(ref object value)
{ {
string text = null; string text = null;
if (ReadAsText(ref text, typeof (Enum))) if (ReadAsText(ref text, typeof(Enum)))
{ {
int number; int number;
if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number)) if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
......
...@@ -82,7 +82,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -82,7 +82,7 @@ namespace Google.ProtocolBuffers.Serialization
{ {
if (obj is IConvertible) if (obj is IConvertible)
{ {
value = (T) Convert.ChangeType(obj, typeof (T), CultureInfo.InvariantCulture); value = (T) Convert.ChangeType(obj, typeof(T), CultureInfo.InvariantCulture);
} }
else else
{ {
...@@ -207,7 +207,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -207,7 +207,7 @@ namespace Google.ProtocolBuffers.Serialization
object[] array = null; object[] array = null;
if (GetValue(ref array)) if (GetValue(ref array))
{ {
if (typeof (T) == typeof (ByteString)) if (typeof(T) == typeof(ByteString))
{ {
ICollection<ByteString> output = (ICollection<ByteString>) items; ICollection<ByteString> output = (ICollection<ByteString>) items;
foreach (byte[] item in array) foreach (byte[] item in array)
......
...@@ -207,7 +207,7 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -207,7 +207,7 @@ namespace Google.ProtocolBuffers.Serialization
//exponent representation of integer number: //exponent representation of integer number:
if (value != null && type == JsonCursor.JsType.Number && if (value != null && type == JsonCursor.JsType.Number &&
(typeInfo != typeof (double) && typeInfo != typeof (float)) && (typeInfo != typeof(double) && typeInfo != typeof(float)) &&
value.IndexOf("e", StringComparison.OrdinalIgnoreCase) > 0) value.IndexOf("e", StringComparison.OrdinalIgnoreCase) > 0)
{ {
value = XmlConvert.ToString((long) Math.Round(XmlConvert.ToDouble(value), 0)); value = XmlConvert.ToString((long) Math.Round(XmlConvert.ToDouble(value), 0));
......
...@@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers ...@@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers
[TestClass] [TestClass]
public class ExtendableMessageTest public class ExtendableMessageTest
{ {
[TestMethod, ExpectedException(typeof (ArgumentException))] [TestMethod, ExpectedException(typeof(ArgumentException))]
public void ExtensionWriterInvalidExtension() public void ExtensionWriterInvalidExtension()
{ {
TestPackedExtensions.CreateBuilder()[UnitTestProtoFile.OptionalForeignMessageExtension.Descriptor] = TestPackedExtensions.CreateBuilder()[UnitTestProtoFile.OptionalForeignMessageExtension.Descriptor] =
......
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using Google.ProtocolBuffers.Descriptors;
using NUnit.Framework;
using UnitTest.Issues.TestProtos;
namespace Google.ProtocolBuffers
{
/// <summary>
/// Tests for issues which aren't easily compartmentalized into other unit tests.
/// </summary>
[TestFixture]
public class IssuesTest
{
// Issue 45
[Test]
public void FieldCalledItem()
{
ItemField message = new ItemField.Builder { Item = 3 }.Build();
FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
Assert.IsNotNull(field);
Assert.AreEqual(3, message[field]);
}
}
}
...@@ -44,14 +44,14 @@ namespace Google.ProtocolBuffers ...@@ -44,14 +44,14 @@ namespace Google.ProtocolBuffers
public class MessageUtilTest public class MessageUtilTest
{ {
[TestMethod] [TestMethod]
[ExpectedException(typeof (ArgumentNullException))] [ExpectedException(typeof(ArgumentNullException))]
public void NullTypeName() public void NullTypeName()
{ {
MessageUtil.GetDefaultMessage((string) null); MessageUtil.GetDefaultMessage((string) null);
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof (ArgumentException))] [ExpectedException(typeof(ArgumentException))]
public void InvalidTypeName() public void InvalidTypeName()
{ {
MessageUtil.GetDefaultMessage("invalidtypename"); MessageUtil.GetDefaultMessage("invalidtypename");
...@@ -61,27 +61,27 @@ namespace Google.ProtocolBuffers ...@@ -61,27 +61,27 @@ namespace Google.ProtocolBuffers
public void ValidTypeName() public void ValidTypeName()
{ {
Assert.AreSame(TestAllTypes.DefaultInstance, Assert.AreSame(TestAllTypes.DefaultInstance,
MessageUtil.GetDefaultMessage(typeof (TestAllTypes).AssemblyQualifiedName)); MessageUtil.GetDefaultMessage(typeof(TestAllTypes).AssemblyQualifiedName));
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof (ArgumentNullException))] [ExpectedException(typeof(ArgumentNullException))]
public void NullType() public void NullType()
{ {
MessageUtil.GetDefaultMessage((Type) null); MessageUtil.GetDefaultMessage((Type) null);
} }
[TestMethod] [TestMethod]
[ExpectedException(typeof (ArgumentException))] [ExpectedException(typeof(ArgumentException))]
public void NonMessageType() public void NonMessageType()
{ {
MessageUtil.GetDefaultMessage(typeof (string)); MessageUtil.GetDefaultMessage(typeof(string));
} }
[TestMethod] [TestMethod]
public void ValidType() public void ValidType()
{ {
Assert.AreSame(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof (TestAllTypes))); Assert.AreSame(TestAllTypes.DefaultInstance, MessageUtil.GetDefaultMessage(typeof(TestAllTypes)));
} }
} }
} }
\ No newline at end of file
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
<Compile Include="ExtendableMessageTest.cs" /> <Compile Include="ExtendableMessageTest.cs" />
<Compile Include="GeneratedBuilderTest.cs" /> <Compile Include="GeneratedBuilderTest.cs" />
<Compile Include="GeneratedMessageTest.cs" /> <Compile Include="GeneratedMessageTest.cs" />
<Compile Include="IssuesTest.cs" />
<Compile Include="MessageStreamIteratorTest.cs" /> <Compile Include="MessageStreamIteratorTest.cs" />
<Compile Include="MessageStreamWriterTest.cs" /> <Compile Include="MessageStreamWriterTest.cs" />
<Compile Include="MessageTest.cs" /> <Compile Include="MessageTest.cs" />
......
...@@ -36,6 +36,8 @@ namespace UnitTest.Issues.TestProtos { ...@@ -36,6 +36,8 @@ namespace UnitTest.Issues.TestProtos {
internal static pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedChild, global::UnitTest.Issues.TestProtos.DeprecatedChild.Builder> internal__static_unittest_issues_DeprecatedChild__FieldAccessorTable; internal static pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedChild, global::UnitTest.Issues.TestProtos.DeprecatedChild.Builder> internal__static_unittest_issues_DeprecatedChild__FieldAccessorTable;
internal static pbd::MessageDescriptor internal__static_unittest_issues_DeprecatedFieldsMessage__Descriptor; internal static pbd::MessageDescriptor internal__static_unittest_issues_DeprecatedFieldsMessage__Descriptor;
internal static pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage, global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage.Builder> internal__static_unittest_issues_DeprecatedFieldsMessage__FieldAccessorTable; internal static pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage, global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage.Builder> internal__static_unittest_issues_DeprecatedFieldsMessage__FieldAccessorTable;
internal static pbd::MessageDescriptor internal__static_unittest_issues_ItemField__Descriptor;
internal static pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.ItemField, global::UnitTest.Issues.TestProtos.ItemField.Builder> internal__static_unittest_issues_ItemField__FieldAccessorTable;
#endregion #endregion
#region Descriptor #region Descriptor
public static pbd::FileDescriptor Descriptor { public static pbd::FileDescriptor Descriptor {
...@@ -63,11 +65,11 @@ namespace UnitTest.Issues.TestProtos { ...@@ -63,11 +65,11 @@ namespace UnitTest.Issues.TestProtos {
"eRgEIAMoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRCAhgB" + "eRgEIAMoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRCAhgB" +
"EjYKCUVudW1WYWx1ZRgFIAEoDjIfLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNh" + "EjYKCUVudW1WYWx1ZRgFIAEoDjIfLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNh" +
"dGVkRW51bUICGAESNgoJRW51bUFycmF5GAYgAygOMh8udW5pdHRlc3RfaXNz" + "dGVkRW51bUICGAESNgoJRW51bUFycmF5GAYgAygOMh8udW5pdHRlc3RfaXNz" +
"dWVzLkRlcHJlY2F0ZWRFbnVtQgIYASpHCgxOZWdhdGl2ZUVudW0SFgoJRml2" + "dWVzLkRlcHJlY2F0ZWRFbnVtQgIYASIZCglJdGVtRmllbGQSDAoEaXRlbRgB" +
"ZUJlbG93EPv//////////wESFQoITWludXNPbmUQ////////////ARIICgRa" + "IAEoBSpHCgxOZWdhdGl2ZUVudW0SFgoJRml2ZUJlbG93EPv//////////wES" +
"ZXJvEAAqGQoORGVwcmVjYXRlZEVudW0SBwoDb25lEAFCQEgBwj47ChpVbml0" + "FQoITWludXNPbmUQ////////////ARIICgRaZXJvEAAqGQoORGVwcmVjYXRl" +
"VGVzdC5Jc3N1ZXMuVGVzdFByb3RvcxIdVW5pdFRlc3RFeHRyYXNJc3N1ZXNQ" + "ZEVudW0SBwoDb25lEAFCQEgBwj47ChpVbml0VGVzdC5Jc3N1ZXMuVGVzdFBy" +
"cm90b0ZpbGU="); "b3RvcxIdVW5pdFRlc3RFeHRyYXNJc3N1ZXNQcm90b0ZpbGU=");
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root; descriptor = root;
internal__static_unittest_issues_A__Descriptor = Descriptor.MessageTypes[0]; internal__static_unittest_issues_A__Descriptor = Descriptor.MessageTypes[0];
...@@ -106,6 +108,10 @@ namespace UnitTest.Issues.TestProtos { ...@@ -106,6 +108,10 @@ namespace UnitTest.Issues.TestProtos {
internal__static_unittest_issues_DeprecatedFieldsMessage__FieldAccessorTable = internal__static_unittest_issues_DeprecatedFieldsMessage__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage, global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage.Builder>(internal__static_unittest_issues_DeprecatedFieldsMessage__Descriptor, new pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage, global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage.Builder>(internal__static_unittest_issues_DeprecatedFieldsMessage__Descriptor,
new string[] { "PrimitiveValue", "PrimitiveArray", "MessageValue", "MessageArray", "EnumValue", "EnumArray", }); new string[] { "PrimitiveValue", "PrimitiveArray", "MessageValue", "MessageArray", "EnumValue", "EnumArray", });
internal__static_unittest_issues_ItemField__Descriptor = Descriptor.MessageTypes[9];
internal__static_unittest_issues_ItemField__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::UnitTest.Issues.TestProtos.ItemField, global::UnitTest.Issues.TestProtos.ItemField.Builder>(internal__static_unittest_issues_ItemField__Descriptor,
new string[] { "Item", });
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance(); pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
RegisterAllExtensions(registry); RegisterAllExtensions(registry);
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry); global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry);
...@@ -3151,6 +3157,280 @@ namespace UnitTest.Issues.TestProtos { ...@@ -3151,6 +3157,280 @@ namespace UnitTest.Issues.TestProtos {
} }
} }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.4.1.473")]
public sealed partial class ItemField : pb::GeneratedMessage<ItemField, ItemField.Builder> {
private ItemField() { }
private static readonly ItemField defaultInstance = new ItemField().MakeReadOnly();
private static readonly string[] _itemFieldFieldNames = new string[] { "item" };
private static readonly uint[] _itemFieldFieldTags = new uint[] { 8 };
public static ItemField DefaultInstance {
get { return defaultInstance; }
}
public override ItemField DefaultInstanceForType {
get { return DefaultInstance; }
}
protected override ItemField ThisMessage {
get { return this; }
}
public static pbd::MessageDescriptor Descriptor {
get { return global::UnitTest.Issues.TestProtos.UnitTestExtrasIssuesProtoFile.internal__static_unittest_issues_ItemField__Descriptor; }
}
protected override pb::FieldAccess.FieldAccessorTable<ItemField, ItemField.Builder> InternalFieldAccessors {
get { return global::UnitTest.Issues.TestProtos.UnitTestExtrasIssuesProtoFile.internal__static_unittest_issues_ItemField__FieldAccessorTable; }
}
public const int ItemFieldNumber = 1;
private bool hasItem;
private int item_;
public bool HasItem {
get { return hasItem; }
}
public int Item {
get { return item_; }
}
public override bool IsInitialized {
get {
return true;
}
}
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
string[] field_names = _itemFieldFieldNames;
if (hasItem) {
output.WriteInt32(1, field_names[0], Item);
}
UnknownFields.WriteTo(output);
}
private int memoizedSerializedSize = -1;
public override int SerializedSize {
get {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (hasItem) {
size += pb::CodedOutputStream.ComputeInt32Size(1, Item);
}
size += UnknownFields.SerializedSize;
memoizedSerializedSize = size;
return size;
}
}
public static ItemField ParseFrom(pb::ByteString data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
}
public static ItemField ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
}
public static ItemField ParseFrom(byte[] data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
}
public static ItemField ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
}
public static ItemField ParseFrom(global::System.IO.Stream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
}
public static ItemField ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static ItemField ParseDelimitedFrom(global::System.IO.Stream input) {
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
}
public static ItemField ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
}
public static ItemField ParseFrom(pb::ICodedInputStream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
}
public static ItemField ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
private ItemField MakeReadOnly() {
return this;
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ItemField prototype) {
return new Builder(prototype);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.4.1.473")]
public sealed partial class Builder : pb::GeneratedBuilder<ItemField, Builder> {
protected override Builder ThisBuilder {
get { return this; }
}
public Builder() {
result = DefaultInstance;
resultIsReadOnly = true;
}
internal Builder(ItemField cloneFrom) {
result = cloneFrom;
resultIsReadOnly = true;
}
private bool resultIsReadOnly;
private ItemField result;
private ItemField PrepareBuilder() {
if (resultIsReadOnly) {
ItemField original = result;
result = new ItemField();
resultIsReadOnly = false;
MergeFrom(original);
}
return result;
}
public override bool IsInitialized {
get { return result.IsInitialized; }
}
protected override ItemField MessageBeingBuilt {
get { return PrepareBuilder(); }
}
public override Builder Clear() {
result = DefaultInstance;
resultIsReadOnly = true;
return this;
}
public override Builder Clone() {
if (resultIsReadOnly) {
return new Builder(result);
} else {
return new Builder().MergeFrom(result);
}
}
public override pbd::MessageDescriptor DescriptorForType {
get { return global::UnitTest.Issues.TestProtos.ItemField.Descriptor; }
}
public override ItemField DefaultInstanceForType {
get { return global::UnitTest.Issues.TestProtos.ItemField.DefaultInstance; }
}
public override ItemField BuildPartial() {
if (resultIsReadOnly) {
return result;
}
resultIsReadOnly = true;
return result.MakeReadOnly();
}
public override Builder MergeFrom(pb::IMessage other) {
if (other is ItemField) {
return MergeFrom((ItemField) other);
} else {
base.MergeFrom(other);
return this;
}
}
public override Builder MergeFrom(ItemField other) {
if (other == global::UnitTest.Issues.TestProtos.ItemField.DefaultInstance) return this;
PrepareBuilder();
if (other.HasItem) {
Item = other.Item;
}
this.MergeUnknownFields(other.UnknownFields);
return this;
}
public override Builder MergeFrom(pb::ICodedInputStream input) {
return MergeFrom(input, pb::ExtensionRegistry.Empty);
}
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
PrepareBuilder();
pb::UnknownFieldSet.Builder unknownFields = null;
uint tag;
string field_name;
while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_itemFieldFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _itemFieldFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) {
case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag();
}
default: {
if (pb::WireFormat.IsEndGroupTag(tag)) {
if (unknownFields != null) {
this.UnknownFields = unknownFields.Build();
}
return this;
}
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
break;
}
case 8: {
result.hasItem = input.ReadInt32(ref result.item_);
break;
}
}
}
if (unknownFields != null) {
this.UnknownFields = unknownFields.Build();
}
return this;
}
public bool HasItem {
get { return result.hasItem; }
}
public int Item {
get { return result.Item; }
set { SetItem(value); }
}
public Builder SetItem(int value) {
PrepareBuilder();
result.hasItem = true;
result.item_ = value;
return this;
}
public Builder ClearItem() {
PrepareBuilder();
result.hasItem = false;
result.item_ = 0;
return this;
}
}
static ItemField() {
object.ReferenceEquals(global::UnitTest.Issues.TestProtos.UnitTestExtrasIssuesProtoFile.Descriptor, null);
}
}
#endregion #endregion
} }
......
...@@ -51,11 +51,11 @@ namespace Google.ProtocolBuffers ...@@ -51,11 +51,11 @@ namespace Google.ProtocolBuffers
[TestMethod] [TestMethod]
public void FieldTypeToWireTypeMapping() public void FieldTypeToWireTypeMapping()
{ {
foreach (FieldInfo field in typeof (FieldType).GetFields(BindingFlags.Static | BindingFlags.Public)) foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
{ {
FieldType fieldType = (FieldType) field.GetValue(null); FieldType fieldType = (FieldType) field.GetValue(null);
FieldMappingAttribute mapping = FieldMappingAttribute mapping =
(FieldMappingAttribute) field.GetCustomAttributes(typeof (FieldMappingAttribute), false)[0]; (FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
Assert.AreEqual(mapping.WireType, WireFormat.GetWireType(fieldType)); Assert.AreEqual(mapping.WireType, WireFormat.GetWireType(fieldType));
} }
} }
......
...@@ -467,7 +467,7 @@ namespace Google.ProtocolBuffers ...@@ -467,7 +467,7 @@ namespace Google.ProtocolBuffers
where T : struct, IComparable, IFormattable, IConvertible where T : struct, IComparable, IFormattable, IConvertible
{ {
int number = (int) ReadRawVarint32(); int number = (int) ReadRawVarint32();
if (Enum.IsDefined(typeof (T), number)) if (Enum.IsDefined(typeof(T), number))
{ {
unknown = null; unknown = null;
value = (T) (object) number; value = (T) (object) number;
......
...@@ -441,11 +441,11 @@ namespace Google.ProtocolBuffers.Descriptors ...@@ -441,11 +441,11 @@ namespace Google.ProtocolBuffers.Descriptors
private static IDictionary<FieldType, MappedType> MapFieldTypes() private static IDictionary<FieldType, MappedType> MapFieldTypes()
{ {
var map = new Dictionary<FieldType, MappedType>(); var map = new Dictionary<FieldType, MappedType>();
foreach (FieldInfo field in typeof (FieldType).GetFields(BindingFlags.Static | BindingFlags.Public)) foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
{ {
FieldType fieldType = (FieldType) field.GetValue(null); FieldType fieldType = (FieldType) field.GetValue(null);
FieldMappingAttribute mapping = FieldMappingAttribute mapping =
(FieldMappingAttribute) field.GetCustomAttributes(typeof (FieldMappingAttribute), false)[0]; (FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
map[fieldType] = mapping.MappedType; map[fieldType] = mapping.MappedType;
} }
return Dictionaries.AsReadOnly(map); return Dictionaries.AsReadOnly(map);
......
...@@ -63,11 +63,11 @@ namespace Google.ProtocolBuffers.Descriptors ...@@ -63,11 +63,11 @@ namespace Google.ProtocolBuffers.Descriptors
private static IDictionary<FieldType, FieldMappingAttribute> MapFieldTypes() private static IDictionary<FieldType, FieldMappingAttribute> MapFieldTypes()
{ {
var map = new Dictionary<FieldType, FieldMappingAttribute>(); var map = new Dictionary<FieldType, FieldMappingAttribute>();
foreach (FieldInfo field in typeof (FieldType).GetFields(BindingFlags.Static | BindingFlags.Public)) foreach (FieldInfo field in typeof(FieldType).GetFields(BindingFlags.Static | BindingFlags.Public))
{ {
FieldType fieldType = (FieldType) field.GetValue(null); FieldType fieldType = (FieldType) field.GetValue(null);
FieldMappingAttribute mapping = FieldMappingAttribute mapping =
(FieldMappingAttribute) field.GetCustomAttributes(typeof (FieldMappingAttribute), false)[0]; (FieldMappingAttribute) field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
map[fieldType] = mapping; map[fieldType] = mapping;
} }
return Dictionaries.AsReadOnly(map); return Dictionaries.AsReadOnly(map);
......
...@@ -107,7 +107,7 @@ namespace Google.ProtocolBuffers ...@@ -107,7 +107,7 @@ namespace Google.ProtocolBuffers
items.Add(Convert.ToInt32(evalue), new EnumValue(evalue)); items.Add(Convert.ToInt32(evalue), new EnumValue(evalue));
} }
#else #else
foreach (TEnum evalue in Enum.GetValues(typeof (TEnum))) foreach (TEnum evalue in Enum.GetValues(typeof(TEnum)))
{ {
items.Add(Convert.ToInt32(evalue), new EnumValue(evalue)); items.Add(Convert.ToInt32(evalue), new EnumValue(evalue));
} }
...@@ -128,9 +128,9 @@ namespace Google.ProtocolBuffers ...@@ -128,9 +128,9 @@ namespace Google.ProtocolBuffers
public IEnumLite FindValueByName(string name) public IEnumLite FindValueByName(string name)
{ {
IEnumLite val; IEnumLite val;
if (Enum.IsDefined(typeof (TEnum), name)) if (Enum.IsDefined(typeof(TEnum), name))
{ {
return items.TryGetValue((int) Enum.Parse(typeof (TEnum), name, false), out val) ? val : null; return items.TryGetValue((int) Enum.Parse(typeof(TEnum), name, false), out val) ? val : null;
} }
return null; return null;
} }
......
...@@ -44,6 +44,11 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -44,6 +44,11 @@ namespace Google.ProtocolBuffers.FieldAccess
/// </summary> /// </summary>
internal static class ReflectionUtil internal static class ReflectionUtil
{ {
/// <summary>
/// Empty Type[] used when calling GetProperty to force property instead of indexer fetching.
/// </summary>
internal static readonly Type[] EmptyTypes = new Type[0];
/// <summary> /// <summary>
/// Creates a delegate which will execute the given method and then return /// Creates a delegate which will execute the given method and then return
/// the result as an object. /// the result as an object.
...@@ -51,8 +56,8 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -51,8 +56,8 @@ namespace Google.ProtocolBuffers.FieldAccess
public static Func<T, object> CreateUpcastDelegate<T>(MethodInfo method) public static Func<T, object> CreateUpcastDelegate<T>(MethodInfo method)
{ {
// The tricky bit is invoking CreateCreateUpcastDelegateImpl with the right type parameters // The tricky bit is invoking CreateCreateUpcastDelegateImpl with the right type parameters
MethodInfo openImpl = typeof (ReflectionUtil).GetMethod("CreateUpcastDelegateImpl"); MethodInfo openImpl = typeof(ReflectionUtil).GetMethod("CreateUpcastDelegateImpl");
MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof (T), method.ReturnType); MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof(T), method.ReturnType);
return (Func<T, object>) closedImpl.Invoke(null, new object[] {method}); return (Func<T, object>) closedImpl.Invoke(null, new object[] {method});
} }
...@@ -66,7 +71,7 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -66,7 +71,7 @@ namespace Google.ProtocolBuffers.FieldAccess
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method() // Convert the reflection call into an open delegate, i.e. instead of calling x.Method()
// we'll call getter(x). // we'll call getter(x).
Func<TSource, TResult> getter = Func<TSource, TResult> getter =
(Func<TSource, TResult>) Delegate.CreateDelegate(typeof (Func<TSource, TResult>), null, method); (Func<TSource, TResult>) Delegate.CreateDelegate(typeof(Func<TSource, TResult>), null, method);
// Implicit upcast to object (within the delegate) // Implicit upcast to object (within the delegate)
return delegate(TSource source) { return getter(source); }; return delegate(TSource source) { return getter(source); };
...@@ -78,8 +83,8 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -78,8 +83,8 @@ namespace Google.ProtocolBuffers.FieldAccess
/// </summary> /// </summary>
public static Action<T, object> CreateDowncastDelegate<T>(MethodInfo method) public static Action<T, object> CreateDowncastDelegate<T>(MethodInfo method)
{ {
MethodInfo openImpl = typeof (ReflectionUtil).GetMethod("CreateDowncastDelegateImpl"); MethodInfo openImpl = typeof(ReflectionUtil).GetMethod("CreateDowncastDelegateImpl");
MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof (T), method.GetParameters()[0].ParameterType); MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof(T), method.GetParameters()[0].ParameterType);
return (Action<T, object>) closedImpl.Invoke(null, new object[] {method}); return (Action<T, object>) closedImpl.Invoke(null, new object[] {method});
} }
...@@ -88,7 +93,7 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -88,7 +93,7 @@ namespace Google.ProtocolBuffers.FieldAccess
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll // Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// call Method(x, y) // call Method(x, y)
Action<TSource, TParam> call = Action<TSource, TParam> call =
(Action<TSource, TParam>) Delegate.CreateDelegate(typeof (Action<TSource, TParam>), null, method); (Action<TSource, TParam>) Delegate.CreateDelegate(typeof(Action<TSource, TParam>), null, method);
return delegate(TSource source, object parameter) { call(source, (TParam) parameter); }; return delegate(TSource source, object parameter) { call(source, (TParam) parameter); };
} }
...@@ -99,8 +104,8 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -99,8 +104,8 @@ namespace Google.ProtocolBuffers.FieldAccess
/// </summary> /// </summary>
public static Action<T, object> CreateDowncastDelegateIgnoringReturn<T>(MethodInfo method) public static Action<T, object> CreateDowncastDelegateIgnoringReturn<T>(MethodInfo method)
{ {
MethodInfo openImpl = typeof (ReflectionUtil).GetMethod("CreateDowncastDelegateIgnoringReturnImpl"); MethodInfo openImpl = typeof(ReflectionUtil).GetMethod("CreateDowncastDelegateIgnoringReturnImpl");
MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof (T), method.GetParameters()[0].ParameterType, MethodInfo closedImpl = openImpl.MakeGenericMethod(typeof(T), method.GetParameters()[0].ParameterType,
method.ReturnType); method.ReturnType);
return (Action<T, object>) closedImpl.Invoke(null, new object[] {method}); return (Action<T, object>) closedImpl.Invoke(null, new object[] {method});
} }
...@@ -111,7 +116,7 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -111,7 +116,7 @@ namespace Google.ProtocolBuffers.FieldAccess
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll // Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// call Method(x, y) // call Method(x, y)
Func<TSource, TParam, TReturn> call = (Func<TSource, TParam, TReturn>) Func<TSource, TParam, TReturn> call = (Func<TSource, TParam, TReturn>)
Delegate.CreateDelegate(typeof (Func<TSource, TParam, TReturn>), null, Delegate.CreateDelegate(typeof(Func<TSource, TParam, TReturn>), null,
method); method);
return delegate(TSource source, object parameter) { call(source, (TParam) parameter); }; return delegate(TSource source, object parameter) { call(source, (TParam) parameter); };
...@@ -122,14 +127,14 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -122,14 +127,14 @@ namespace Google.ProtocolBuffers.FieldAccess
/// </summary> /// </summary>
public static Func<IBuilder> CreateStaticUpcastDelegate(MethodInfo method) public static Func<IBuilder> CreateStaticUpcastDelegate(MethodInfo method)
{ {
MethodInfo openImpl = typeof (ReflectionUtil).GetMethod("CreateStaticUpcastDelegateImpl"); MethodInfo openImpl = typeof(ReflectionUtil).GetMethod("CreateStaticUpcastDelegateImpl");
MethodInfo closedImpl = openImpl.MakeGenericMethod(method.ReturnType); MethodInfo closedImpl = openImpl.MakeGenericMethod(method.ReturnType);
return (Func<IBuilder>) closedImpl.Invoke(null, new object[] {method}); return (Func<IBuilder>) closedImpl.Invoke(null, new object[] {method});
} }
public static Func<IBuilder> CreateStaticUpcastDelegateImpl<T>(MethodInfo method) public static Func<IBuilder> CreateStaticUpcastDelegateImpl<T>(MethodInfo method)
{ {
Func<T> call = (Func<T>) Delegate.CreateDelegate(typeof (Func<T>), null, method); Func<T> call = (Func<T>) Delegate.CreateDelegate(typeof(Func<T>), null, method);
return delegate { return (IBuilder) call(); }; return delegate { return (IBuilder) call(); };
} }
} }
......
...@@ -66,14 +66,14 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -66,14 +66,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal RepeatedPrimitiveAccessor(string name) internal RepeatedPrimitiveAccessor(string name)
{ {
PropertyInfo messageProperty = typeof (TMessage).GetProperty(name + "List"); PropertyInfo messageProperty = typeof(TMessage).GetProperty(name + "List", ReflectionUtil.EmptyTypes);
PropertyInfo builderProperty = typeof (TBuilder).GetProperty(name + "List"); PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name + "List", ReflectionUtil.EmptyTypes);
PropertyInfo countProperty = typeof (TMessage).GetProperty(name + "Count"); PropertyInfo countProperty = typeof(TMessage).GetProperty(name + "Count", ReflectionUtil.EmptyTypes);
MethodInfo clearMethod = typeof (TBuilder).GetMethod("Clear" + name, EmptyTypes); MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name, EmptyTypes);
getElementMethod = typeof (TMessage).GetMethod("Get" + name, new Type[] {typeof (int)}); getElementMethod = typeof(TMessage).GetMethod("Get" + name, new Type[] {typeof(int)});
clrType = getElementMethod.ReturnType; clrType = getElementMethod.ReturnType;
MethodInfo addMethod = typeof (TBuilder).GetMethod("Add" + name, new Type[] {ClrType}); MethodInfo addMethod = typeof(TBuilder).GetMethod("Add" + name, new Type[] {ClrType});
setElementMethod = typeof (TBuilder).GetMethod("Set" + name, new Type[] {typeof (int), ClrType}); setElementMethod = typeof(TBuilder).GetMethod("Set" + name, new Type[] {typeof(int), ClrType});
if (messageProperty == null if (messageProperty == null
|| builderProperty == null || builderProperty == null
|| countProperty == null || countProperty == null
...@@ -85,9 +85,9 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -85,9 +85,9 @@ namespace Google.ProtocolBuffers.FieldAccess
throw new ArgumentException("Not all required properties/methods available"); throw new ArgumentException("Not all required properties/methods available");
} }
clearDelegate = clearDelegate =
(Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof (Func<TBuilder, IBuilder>), null, clearMethod); (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), null, clearMethod);
countDelegate = (Func<TMessage, int>) Delegate.CreateDelegate countDelegate = (Func<TMessage, int>) Delegate.CreateDelegate
(typeof (Func<TMessage, int>), null, countProperty.GetGetMethod()); (typeof(Func<TMessage, int>), null, countProperty.GetGetMethod());
getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod()); getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod());
addValueDelegate = ReflectionUtil.CreateDowncastDelegateIgnoringReturn<TBuilder>(addMethod); addValueDelegate = ReflectionUtil.CreateDowncastDelegateIgnoringReturn<TBuilder>(addMethod);
getRepeatedWrapperDelegate = ReflectionUtil.CreateUpcastDelegate<TBuilder>(builderProperty.GetGetMethod()); getRepeatedWrapperDelegate = ReflectionUtil.CreateUpcastDelegate<TBuilder>(builderProperty.GetGetMethod());
......
...@@ -50,7 +50,7 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -50,7 +50,7 @@ namespace Google.ProtocolBuffers.FieldAccess
internal SingleMessageAccessor(string name) : base(name) internal SingleMessageAccessor(string name) : base(name)
{ {
MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", EmptyTypes); MethodInfo createBuilderMethod = ClrType.GetMethod("CreateBuilder", ReflectionUtil.EmptyTypes);
if (createBuilderMethod == null) if (createBuilderMethod == null)
{ {
throw new ArgumentException("No public static CreateBuilder method declared in " + ClrType.Name); throw new ArgumentException("No public static CreateBuilder method declared in " + ClrType.Name);
......
...@@ -47,8 +47,6 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -47,8 +47,6 @@ namespace Google.ProtocolBuffers.FieldAccess
private readonly Func<TMessage, bool> hasDelegate; private readonly Func<TMessage, bool> hasDelegate;
private readonly Func<TBuilder, IBuilder> clearDelegate; private readonly Func<TBuilder, IBuilder> clearDelegate;
internal static readonly Type[] EmptyTypes = new Type[0];
/// <summary> /// <summary>
/// The CLR type of the field (int, the enum type, ByteString, the message etc). /// The CLR type of the field (int, the enum type, ByteString, the message etc).
/// As declared by the property. /// As declared by the property.
...@@ -60,14 +58,14 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -60,14 +58,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal SinglePrimitiveAccessor(string name) internal SinglePrimitiveAccessor(string name)
{ {
PropertyInfo messageProperty = typeof (TMessage).GetProperty(name); PropertyInfo messageProperty = typeof(TMessage).GetProperty(name, ReflectionUtil.EmptyTypes);
PropertyInfo builderProperty = typeof (TBuilder).GetProperty(name); PropertyInfo builderProperty = typeof(TBuilder).GetProperty(name, ReflectionUtil.EmptyTypes);
if (builderProperty == null) if (builderProperty == null)
{ {
builderProperty = typeof (TBuilder).GetProperty(name); builderProperty = typeof(TBuilder).GetProperty(name, ReflectionUtil.EmptyTypes);
} }
PropertyInfo hasProperty = typeof (TMessage).GetProperty("Has" + name); PropertyInfo hasProperty = typeof(TMessage).GetProperty("Has" + name, ReflectionUtil.EmptyTypes);
MethodInfo clearMethod = typeof (TBuilder).GetMethod("Clear" + name, EmptyTypes); MethodInfo clearMethod = typeof(TBuilder).GetMethod("Clear" + name, ReflectionUtil.EmptyTypes);
if (messageProperty == null || builderProperty == null || hasProperty == null || clearMethod == null) if (messageProperty == null || builderProperty == null || hasProperty == null || clearMethod == null)
{ {
throw new ArgumentException("Not all required properties/methods available"); throw new ArgumentException("Not all required properties/methods available");
...@@ -75,9 +73,9 @@ namespace Google.ProtocolBuffers.FieldAccess ...@@ -75,9 +73,9 @@ namespace Google.ProtocolBuffers.FieldAccess
clrType = messageProperty.PropertyType; clrType = messageProperty.PropertyType;
hasDelegate = hasDelegate =
(Func<TMessage, bool>) (Func<TMessage, bool>)
Delegate.CreateDelegate(typeof (Func<TMessage, bool>), null, hasProperty.GetGetMethod()); Delegate.CreateDelegate(typeof(Func<TMessage, bool>), null, hasProperty.GetGetMethod());
clearDelegate = clearDelegate =
(Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof (Func<TBuilder, IBuilder>), null, clearMethod); (Func<TBuilder, IBuilder>) Delegate.CreateDelegate(typeof(Func<TBuilder, IBuilder>), null, clearMethod);
getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod()); getValueDelegate = ReflectionUtil.CreateUpcastDelegate<TMessage>(messageProperty.GetGetMethod());
setValueDelegate = ReflectionUtil.CreateDowncastDelegate<TBuilder>(builderProperty.GetSetMethod()); setValueDelegate = ReflectionUtil.CreateDowncastDelegate<TBuilder>(builderProperty.GetSetMethod());
} }
......
...@@ -85,7 +85,7 @@ namespace Google.ProtocolBuffers ...@@ -85,7 +85,7 @@ namespace Google.ProtocolBuffers
if (defaultInstanceProperty == null) if (defaultInstanceProperty == null)
{ {
throw new ArgumentException("No public static DefaultInstance property for type " + throw new ArgumentException("No public static DefaultInstance property for type " +
typeof (TExtension).Name); typeof(TExtension).Name);
} }
messageDefaultInstance = (IMessageLite) defaultInstanceProperty.GetValue(null, null); messageDefaultInstance = (IMessageLite) defaultInstanceProperty.GetValue(null, null);
......
...@@ -46,7 +46,7 @@ namespace Google.ProtocolBuffers ...@@ -46,7 +46,7 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
public sealed class GeneratedRepeatExtension<TExtensionElement> : GeneratedExtensionBase<IList<TExtensionElement>> public sealed class GeneratedRepeatExtension<TExtensionElement> : GeneratedExtensionBase<IList<TExtensionElement>>
{ {
private GeneratedRepeatExtension(FieldDescriptor field) : base(field, typeof (TExtensionElement)) private GeneratedRepeatExtension(FieldDescriptor field) : base(field, typeof(TExtensionElement))
{ {
} }
......
...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers ...@@ -44,7 +44,7 @@ namespace Google.ProtocolBuffers
/// </remarks> /// </remarks>
public sealed class GeneratedSingleExtension<TExtension> : GeneratedExtensionBase<TExtension> public sealed class GeneratedSingleExtension<TExtension> : GeneratedExtensionBase<TExtension>
{ {
internal GeneratedSingleExtension(FieldDescriptor descriptor) : base(descriptor, typeof (TExtension)) internal GeneratedSingleExtension(FieldDescriptor descriptor) : base(descriptor, typeof(TExtension))
{ {
} }
......
...@@ -84,16 +84,16 @@ namespace Google.ProtocolBuffers ...@@ -84,16 +84,16 @@ namespace Google.ProtocolBuffers
Type builderType = FindBuilderType(); Type builderType = FindBuilderType();
// Yes, it's redundant to find this again, but it's only the once... // Yes, it's redundant to find this again, but it's only the once...
MethodInfo createBuilderMethod = typeof (TMessage).GetMethod("CreateBuilder", EmptyTypes); MethodInfo createBuilderMethod = typeof(TMessage).GetMethod("CreateBuilder", EmptyTypes);
Delegate builderBuilder = Delegate.CreateDelegate( Delegate builderBuilder = Delegate.CreateDelegate(
typeof (Func<>).MakeGenericType(builderType), null, createBuilderMethod); typeof(Func<>).MakeGenericType(builderType), null, createBuilderMethod);
MethodInfo buildMethod = typeof (MessageStreamIterator<TMessage>) MethodInfo buildMethod = typeof(MessageStreamIterator<TMessage>)
.GetMethod("BuildImpl", BindingFlags.Static | BindingFlags.NonPublic) .GetMethod("BuildImpl", BindingFlags.Static | BindingFlags.NonPublic)
.MakeGenericMethod(typeof (TMessage), builderType); .MakeGenericMethod(typeof(TMessage), builderType);
return (Func<CodedInputStream, ExtensionRegistry, TMessage>) Delegate.CreateDelegate( return (Func<CodedInputStream, ExtensionRegistry, TMessage>) Delegate.CreateDelegate(
typeof (Func<CodedInputStream, ExtensionRegistry, TMessage>), builderBuilder, buildMethod); typeof(Func<CodedInputStream, ExtensionRegistry, TMessage>), builderBuilder, buildMethod);
} }
catch (ArgumentException e) catch (ArgumentException e)
{ {
...@@ -116,28 +116,28 @@ namespace Google.ProtocolBuffers ...@@ -116,28 +116,28 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
private static Type FindBuilderType() private static Type FindBuilderType()
{ {
MethodInfo createBuilderMethod = typeof (TMessage).GetMethod("CreateBuilder", EmptyTypes); MethodInfo createBuilderMethod = typeof(TMessage).GetMethod("CreateBuilder", EmptyTypes);
if (createBuilderMethod == null) if (createBuilderMethod == null)
{ {
throw new ArgumentException("Message type " + typeof (TMessage).FullName + throw new ArgumentException("Message type " + typeof(TMessage).FullName +
" has no CreateBuilder method."); " has no CreateBuilder method.");
} }
if (createBuilderMethod.ReturnType == typeof (void)) if (createBuilderMethod.ReturnType == typeof(void))
{ {
throw new ArgumentException("CreateBuilder method in " + typeof (TMessage).FullName + throw new ArgumentException("CreateBuilder method in " + typeof(TMessage).FullName +
" has void return type"); " has void return type");
} }
Type builderType = createBuilderMethod.ReturnType; Type builderType = createBuilderMethod.ReturnType;
Type messageInterface = typeof (IMessage<,>).MakeGenericType(typeof (TMessage), builderType); Type messageInterface = typeof(IMessage<,>).MakeGenericType(typeof(TMessage), builderType);
Type builderInterface = typeof (IBuilder<,>).MakeGenericType(typeof (TMessage), builderType); Type builderInterface = typeof(IBuilder<,>).MakeGenericType(typeof(TMessage), builderType);
if (Array.IndexOf(typeof (TMessage).GetInterfaces(), messageInterface) == -1) if (Array.IndexOf(typeof(TMessage).GetInterfaces(), messageInterface) == -1)
{ {
throw new ArgumentException("Message type " + typeof (TMessage) + " doesn't implement " + throw new ArgumentException("Message type " + typeof(TMessage) + " doesn't implement " +
messageInterface.FullName); messageInterface.FullName);
} }
if (Array.IndexOf(builderType.GetInterfaces(), builderInterface) == -1) if (Array.IndexOf(builderType.GetInterfaces(), builderInterface) == -1)
{ {
throw new ArgumentException("Builder type " + typeof (TMessage) + " doesn't implement " + throw new ArgumentException("Builder type " + typeof(TMessage) + " doesn't implement " +
builderInterface.FullName); builderInterface.FullName);
} }
return builderType; return builderType;
......
...@@ -65,7 +65,7 @@ namespace Google.ProtocolBuffers ...@@ -65,7 +65,7 @@ namespace Google.ProtocolBuffers
throw new ArgumentException("Unable to get a default message for an abstract or generic type (" + throw new ArgumentException("Unable to get a default message for an abstract or generic type (" +
type.FullName + ")"); type.FullName + ")");
} }
if (!typeof (IMessage).IsAssignableFrom(type)) if (!typeof(IMessage).IsAssignableFrom(type))
{ {
throw new ArgumentException("Unable to get a default message for non-message type (" + type.FullName + throw new ArgumentException("Unable to get a default message for non-message type (" + type.FullName +
")"); ")");
......
...@@ -255,7 +255,7 @@ namespace Google.ProtocolBuffers ...@@ -255,7 +255,7 @@ namespace Google.ProtocolBuffers
TestUtil.AssertBytesEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray()); TestUtil.AssertBytesEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray());
} }
[TestMethod, ExpectedException(typeof (UninitializedMessageException))] [TestMethod, ExpectedException(typeof(UninitializedMessageException))]
public void TestIBuilderLiteWeakBuildUninitialized() public void TestIBuilderLiteWeakBuildUninitialized()
{ {
IBuilderLite builder = TestRequiredLite.CreateBuilder(); IBuilderLite builder = TestRequiredLite.CreateBuilder();
......
...@@ -111,7 +111,7 @@ namespace Google.ProtocolBuffers ...@@ -111,7 +111,7 @@ namespace Google.ProtocolBuffers
public void TestIMessageLiteWeakCreateBuilderForType() public void TestIMessageLiteWeakCreateBuilderForType()
{ {
IMessageLite msg = TestRequiredLite.DefaultInstance; IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.AreEqual(typeof (TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType()); Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
} }
[TestMethod] [TestMethod]
......
...@@ -128,7 +128,7 @@ namespace Google.ProtocolBuffers ...@@ -128,7 +128,7 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i));
} }
[TestMethod, ExpectedException(typeof (ArgumentOutOfRangeException))] [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestGetExtensionTIndexOutOfRange() public void TestGetExtensionTIndexOutOfRange()
{ {
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
...@@ -154,7 +154,7 @@ namespace Google.ProtocolBuffers ...@@ -154,7 +154,7 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(5 + i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); Assert.AreEqual(5 + i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i));
} }
[TestMethod, ExpectedException(typeof (ArgumentOutOfRangeException))] [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestSetExtensionTIndexOutOfRange() public void TestSetExtensionTIndexOutOfRange()
{ {
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
...@@ -209,7 +209,7 @@ namespace Google.ProtocolBuffers ...@@ -209,7 +209,7 @@ namespace Google.ProtocolBuffers
Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0)); Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0));
} }
[TestMethod, ExpectedException(typeof (ArgumentOutOfRangeException))] [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestIndexedByDescriptorAndOrdinalOutOfRange() public void TestIndexedByDescriptorAndOrdinalOutOfRange()
{ {
TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
......
...@@ -47,7 +47,7 @@ namespace Google.ProtocolBuffers ...@@ -47,7 +47,7 @@ namespace Google.ProtocolBuffers
public class ExtendableMessageLiteTest public class ExtendableMessageLiteTest
{ {
//The lite framework does not make this assertion //The lite framework does not make this assertion
//[TestMethod, Ignore, ExpectedException(typeof (ArgumentException))] //[TestMethod, Ignore, ExpectedException(typeof(ArgumentException))]
//public void ExtensionWriterInvalidExtension() //public void ExtensionWriterInvalidExtension()
//{ //{
// TestPackedExtensionsLite.CreateBuilder()[ // TestPackedExtensionsLite.CreateBuilder()[
......
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