From c9bce45a01cc8861ec7c88e84d947ed6ebc8f7d1 Mon Sep 17 00:00:00 2001 From: csharptest Date: Sun, 14 Oct 2012 23:03:24 -0500 Subject: Portability Changes - Removing uses of Enum to IConvertible from CodedIOStreams, Removed MessageStreamIterator.FromFile on non-client profiles, Removed use of Path.GetFileName, Removed uses of Converter delegate, Removed Guid/DispId options from test protos --- .../Http/MessageFormatFactory.cs | 4 +-- .../Http/MessageFormatOptions.cs | 37 ++++++++++++++-------- src/ProtocolBuffers.Test/DeprecatedMemberTest.cs | 2 +- src/ProtocolBuffers.Test/GeneratedBuilderTest.cs | 4 ++- .../TestProtos/UnitTestRpcInterop.cs | 13 +++----- src/ProtocolBuffers/CodedInputStream.cs | 4 +-- .../CodedOutputStream.ComputeSize.cs | 4 +-- src/ProtocolBuffers/CodedOutputStream.cs | 4 +-- src/ProtocolBuffers/Descriptors/FileDescriptor.cs | 4 ++- src/ProtocolBuffers/ICodedInputStream.cs | 4 +-- src/ProtocolBuffers/ICodedOutputStream.cs | 4 +-- src/ProtocolBuffers/MessageStreamIterator.cs | 2 ++ src/ProtocolBuffers/TextFormat.cs | 2 +- src/ProtocolBuffers/TextTokenizer.cs | 2 +- .../TestProtos/UnitTestRpcInteropLite.cs | 2 -- 15 files changed, 51 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs b/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs index b3679bab..270af64b 100644 --- a/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs +++ b/src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs @@ -78,7 +78,7 @@ namespace Google.ProtocolBuffers.Serialization.Http { contentType = (contentType ?? String.Empty).Split(';')[0].Trim(); - Converter factory; + CodedInputBuilder factory; if(!options.MimeInputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null) { if(String.IsNullOrEmpty(options.DefaultContentType) || @@ -95,7 +95,7 @@ namespace Google.ProtocolBuffers.Serialization.Http { contentType = (contentType ?? String.Empty).Split(';')[0].Trim(); - Converter factory; + CodedOutputBuilder factory; if (!options.MimeOutputTypesReadOnly.TryGetValue(contentType, out factory) || factory == null) { if (String.IsNullOrEmpty(options.DefaultContentType) || diff --git a/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs b/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs index 72d73717..1480e50a 100644 --- a/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs +++ b/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs @@ -5,6 +5,15 @@ using Google.ProtocolBuffers.Collections; namespace Google.ProtocolBuffers.Serialization.Http { + /// + /// A delegate used to specify a method that constructs an ICodedInputStream from a .NET Stream. + /// + public delegate ICodedInputStream CodedInputBuilder(Stream stream); + /// + /// A delegate used to specify a method that constructs an ICodedOutputStream from a .NET Stream. + /// + public delegate ICodedOutputStream CodedOutputBuilder(Stream stream); + /// /// Defines control information for the various formatting used with HTTP services /// @@ -32,9 +41,9 @@ namespace Google.ProtocolBuffers.Serialization.Http /// /// Default mime-type handling for input /// - private static readonly IDictionary> MimeInputDefaults = - new ReadOnlyDictionary>( - new Dictionary>(StringComparer.OrdinalIgnoreCase) + private static readonly IDictionary MimeInputDefaults = + new ReadOnlyDictionary( + new Dictionary(StringComparer.OrdinalIgnoreCase) { {"application/json", JsonFormatReader.CreateInstance}, {"application/x-json", JsonFormatReader.CreateInstance}, @@ -55,9 +64,9 @@ namespace Google.ProtocolBuffers.Serialization.Http /// /// Default mime-type handling for output /// - private static readonly IDictionary> MimeOutputDefaults = - new ReadOnlyDictionary>( - new Dictionary>(StringComparer.OrdinalIgnoreCase) + private static readonly IDictionary MimeOutputDefaults = + new ReadOnlyDictionary( + new Dictionary(StringComparer.OrdinalIgnoreCase) { {"application/json", JsonFormatWriter.CreateInstance}, {"application/x-json", JsonFormatWriter.CreateInstance}, @@ -81,35 +90,35 @@ namespace Google.ProtocolBuffers.Serialization.Http private string _xmlReaderRootElementName; private string _xmlWriterRootElementName; private ExtensionRegistry _extensionRegistry; - private Dictionary> _mimeInputTypes; - private Dictionary> _mimeOutputTypes; + private Dictionary _mimeInputTypes; + private Dictionary _mimeOutputTypes; /// Provides access to modify the mime-type input stream construction - public IDictionary> MimeInputTypes + public IDictionary MimeInputTypes { get { return _mimeInputTypes ?? - (_mimeInputTypes = new Dictionary>( + (_mimeInputTypes = new Dictionary( MimeInputDefaults, StringComparer.OrdinalIgnoreCase)); } } /// Provides access to modify the mime-type input stream construction - public IDictionary> MimeOutputTypes + public IDictionary MimeOutputTypes { get { return _mimeOutputTypes ?? - (_mimeOutputTypes = new Dictionary>( + (_mimeOutputTypes = new Dictionary( MimeOutputDefaults, StringComparer.OrdinalIgnoreCase)); } } - internal IDictionary> MimeInputTypesReadOnly + internal IDictionary MimeInputTypesReadOnly { get { return _mimeInputTypes ?? MimeInputDefaults; } } - internal IDictionary> MimeOutputTypesReadOnly + internal IDictionary MimeOutputTypesReadOnly { get { return _mimeOutputTypes ?? MimeOutputDefaults; } } /// diff --git a/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs b/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs index 6035c405..0901f043 100644 --- a/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs +++ b/src/ProtocolBuffers.Test/DeprecatedMemberTest.cs @@ -10,7 +10,7 @@ namespace Google.ProtocolBuffers [TestClass] public class DeprecatedMemberTest { - private static void AssertIsDeprecated(ICustomAttributeProvider member) + private static void AssertIsDeprecated(MemberInfo member) { Assert.IsNotNull(member); Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member); diff --git a/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs b/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs index cd870054..1dcb1c21 100644 --- a/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs +++ b/src/ProtocolBuffers.Test/GeneratedBuilderTest.cs @@ -54,7 +54,9 @@ namespace Google.ProtocolBuffers b.AddRangeRepeatedForeignEnum(new OneTimeEnumerator(ForeignEnum.FOREIGN_BAR)); } - private static void AssertThrows(System.Threading.ThreadStart method) where T : Exception + private delegate void TestMethod(); + + private static void AssertThrows(TestMethod method) where T : Exception { try { diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs index 8830b82d..ecffc6f8 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestRpcInterop.cs @@ -39,12 +39,11 @@ namespace Google.ProtocolBuffers.TestProtos { "dHMYASADKAsyGi5TZWFyY2hSZXNwb25zZS5SZXN1bHRJdGVtGicKClJlc3Vs" + "dEl0ZW0SCwoDdXJsGAEgAigJEgwKBG5hbWUYAiABKAkiUgoTUmVmaW5lU2Vh" + "cmNoUmVxdWVzdBIQCghDcml0ZXJpYRgBIAMoCRIpChBwcmV2aW91c19yZXN1" + - "bHRzGAIgAigLMg8uU2VhcmNoUmVzcG9uc2UypQEKDVNlYXJjaFNlcnZpY2US" + - "MAoGU2VhcmNoEg4uU2VhcmNoUmVxdWVzdBoPLlNlYXJjaFJlc3BvbnNlIgXC" + - "PgIIBRI1CgxSZWZpbmVTZWFyY2gSFC5SZWZpbmVTZWFyY2hSZXF1ZXN0Gg8u" + - "U2VhcmNoUmVzcG9uc2UaK8I+KAome0E2NUYwOTI1LUZEMTEtNGY5NC1CMTY2" + - "LTg5QUM0RjAyNzIwNX1CP0gBwj46CiFHb29nbGUuUHJvdG9jb2xCdWZmZXJz" + - "LlRlc3RQcm90b3MSElVuaXRUZXN0UnBjSW50ZXJvcIgOAw=="); + "bHRzGAIgAigLMg8uU2VhcmNoUmVzcG9uc2UycQoNU2VhcmNoU2VydmljZRIp" + + "CgZTZWFyY2gSDi5TZWFyY2hSZXF1ZXN0Gg8uU2VhcmNoUmVzcG9uc2USNQoM" + + "UmVmaW5lU2VhcmNoEhQuUmVmaW5lU2VhcmNoUmVxdWVzdBoPLlNlYXJjaFJl" + + "c3BvbnNlQj9IAcI+OgohR29vZ2xlLlByb3RvY29sQnVmZmVycy5UZXN0UHJv" + + "dG9zEhJVbml0VGVzdFJwY0ludGVyb3CIDgM="); pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { descriptor = root; internal__static_SearchRequest__Descriptor = Descriptor.MessageTypes[0]; @@ -1352,9 +1351,7 @@ namespace Google.ProtocolBuffers.TestProtos { #endregion #region Services - [global::System.Runtime.InteropServices.GuidAttribute("a65f0925-fd11-4f94-b166-89ac4f027205")] public partial interface ISearchService { - [global::System.Runtime.InteropServices.DispId(5)] global::Google.ProtocolBuffers.TestProtos.SearchResponse Search(global::Google.ProtocolBuffers.TestProtos.SearchRequest searchRequest); global::Google.ProtocolBuffers.TestProtos.SearchResponse RefineSearch(global::Google.ProtocolBuffers.TestProtos.RefineSearchRequest refineSearchRequest); } diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs index e4d690b5..ab18f9d7 100644 --- a/src/ProtocolBuffers/CodedInputStream.cs +++ b/src/ProtocolBuffers/CodedInputStream.cs @@ -449,7 +449,7 @@ namespace Google.ProtocolBuffers /// [CLSCompliant(false)] public bool ReadEnum(ref T value, out object unknown) - where T : struct, IComparable, IFormattable, IConvertible + where T : struct, IComparable, IFormattable { int number = (int) ReadRawVarint32(); if (Enum.IsDefined(typeof(T), number)) @@ -882,7 +882,7 @@ namespace Google.ProtocolBuffers [CLSCompliant(false)] public void ReadEnumArray(uint fieldTag, string fieldName, ICollection list, out ICollection unknown) - where T : struct, IComparable, IFormattable, IConvertible + where T : struct, IComparable, IFormattable { unknown = null; object unkval; diff --git a/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs b/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs index 4f4e13d8..ca6662a4 100644 --- a/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs +++ b/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs @@ -575,7 +575,7 @@ namespace Google.ProtocolBuffers case FieldType.Enum: if (value is Enum) { - return ComputeEnumSize(fieldNumber, ((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture)); + return ComputeEnumSize(fieldNumber, Convert.ToInt32(value)); } else { @@ -631,7 +631,7 @@ namespace Google.ProtocolBuffers case FieldType.Enum: if (value is Enum) { - return ComputeEnumSizeNoTag(((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture)); + return ComputeEnumSizeNoTag(Convert.ToInt32(value)); } else { diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs index b6a501c4..b767f705 100644 --- a/src/ProtocolBuffers/CodedOutputStream.cs +++ b/src/ProtocolBuffers/CodedOutputStream.cs @@ -806,7 +806,7 @@ namespace Google.ProtocolBuffers [CLSCompliant(false)] public void WriteEnumArray(int fieldNumber, string fieldName, IEnumerable list) - where T : struct, IComparable, IFormattable, IConvertible + where T : struct, IComparable, IFormattable { if (list is ICastArray) { @@ -1028,7 +1028,7 @@ namespace Google.ProtocolBuffers [CLSCompliant(false)] public void WritePackedEnumArray(int fieldNumber, string fieldName, int calculatedSize, IEnumerable list) - where T : struct, IComparable, IFormattable, IConvertible + where T : struct, IComparable, IFormattable { WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); WriteRawVarint32((uint) calculatedSize); diff --git a/src/ProtocolBuffers/Descriptors/FileDescriptor.cs b/src/ProtocolBuffers/Descriptors/FileDescriptor.cs index 392db9a7..d7075e35 100644 --- a/src/ProtocolBuffers/Descriptors/FileDescriptor.cs +++ b/src/ProtocolBuffers/Descriptors/FileDescriptor.cs @@ -90,12 +90,14 @@ namespace Google.ProtocolBuffers.Descriptors csharpFileOptions = BuildOrFakeWithDefaultOptions(options); } + static readonly char[] PathSeperators = new char[] { '/', '\\' }; private CSharpFileOptions BuildOrFakeWithDefaultOptions(CSharpFileOptions defaultOptions) { // Fix for being able to relocate these files to any directory structure if (proto.Package == "google.protobuf") { - string filename = Path.GetFileName(proto.Name); + int ixslash = proto.Name.LastIndexOfAny(PathSeperators); + string filename = ixslash < 0 ? proto.Name : proto.Name.Substring(ixslash + 1); // TODO(jonskeet): Check if we could use FileDescriptorProto.Descriptor.Name - interesting bootstrap issues) if (filename == "descriptor.proto") { diff --git a/src/ProtocolBuffers/ICodedInputStream.cs b/src/ProtocolBuffers/ICodedInputStream.cs index a3c0f30b..b39b602d 100644 --- a/src/ProtocolBuffers/ICodedInputStream.cs +++ b/src/ProtocolBuffers/ICodedInputStream.cs @@ -171,7 +171,7 @@ namespace Google.ProtocolBuffers /// [CLSCompliant(false)] bool ReadEnum(ref T value, out object unknown) - where T : struct, IComparable, IFormattable, IConvertible; + where T : struct, IComparable, IFormattable; /// /// Reads an sfixed32 field value from the stream. @@ -214,7 +214,7 @@ namespace Google.ProtocolBuffers /// [CLSCompliant(false)] void ReadEnumArray(uint fieldTag, string fieldName, ICollection list, out ICollection unknown) - where T : struct, IComparable, IFormattable, IConvertible; + where T : struct, IComparable, IFormattable; /// /// Reads a set of messages using the as a template. T is not guaranteed to be diff --git a/src/ProtocolBuffers/ICodedOutputStream.cs b/src/ProtocolBuffers/ICodedOutputStream.cs index 8619508a..64c80653 100644 --- a/src/ProtocolBuffers/ICodedOutputStream.cs +++ b/src/ProtocolBuffers/ICodedOutputStream.cs @@ -292,7 +292,7 @@ namespace Google.ProtocolBuffers /// [CLSCompliant(false)] void WriteEnumArray(int fieldNumber, string fieldName, IEnumerable list) - where T : struct, IComparable, IFormattable, IConvertible; + where T : struct, IComparable, IFormattable; /// /// Writes a packed repeated primitive, including tag and length, to the stream. @@ -369,6 +369,6 @@ namespace Google.ProtocolBuffers /// [CLSCompliant(false)] void WritePackedEnumArray(int fieldNumber, string fieldName, int calculatedSize, IEnumerable list) - where T : struct, IComparable, IFormattable, IConvertible; + where T : struct, IComparable, IFormattable; } } \ No newline at end of file diff --git a/src/ProtocolBuffers/MessageStreamIterator.cs b/src/ProtocolBuffers/MessageStreamIterator.cs index 89fda91f..32d697ca 100644 --- a/src/ProtocolBuffers/MessageStreamIterator.cs +++ b/src/ProtocolBuffers/MessageStreamIterator.cs @@ -124,10 +124,12 @@ namespace Google.ProtocolBuffers return new MessageStreamIterator(streamProvider, extensionRegistry, newSizeLimit); } +#if CLIENTPROFILE public static MessageStreamIterator FromFile(string file) { return new MessageStreamIterator(() => File.OpenRead(file), ExtensionRegistry.Empty); } +#endif public static MessageStreamIterator FromStreamProvider(StreamProvider streamProvider) { diff --git a/src/ProtocolBuffers/TextFormat.cs b/src/ProtocolBuffers/TextFormat.cs index c0f4a5f6..7e2eff04 100644 --- a/src/ProtocolBuffers/TextFormat.cs +++ b/src/ProtocolBuffers/TextFormat.cs @@ -708,7 +708,7 @@ namespace Google.ProtocolBuffers { // Explicitly specify the invariant culture so that this code does not break when // executing in Turkey. - String lowerName = name.ToLower(FrameworkPortability.InvariantCulture); + String lowerName = name.ToLowerInvariant(); field = type.FindDescriptor(lowerName); // If the case-insensitive match worked but the field is NOT a group, // TODO(jonskeet): What? Java comment ends here! diff --git a/src/ProtocolBuffers/TextTokenizer.cs b/src/ProtocolBuffers/TextTokenizer.cs index 90774bc2..5bb27fd0 100644 --- a/src/ProtocolBuffers/TextTokenizer.cs +++ b/src/ProtocolBuffers/TextTokenizer.cs @@ -338,7 +338,7 @@ namespace Google.ProtocolBuffers NextToken(); return negative ? double.NegativeInfinity : double.PositiveInfinity; } - if (currentToken.Equals("nan", StringComparison.InvariantCultureIgnoreCase)) + if (currentToken.Equals("nan", StringComparison.OrdinalIgnoreCase)) { NextToken(); return Double.NaN; diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestRpcInteropLite.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestRpcInteropLite.cs index 85f562b4..1a54e8e2 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestRpcInteropLite.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestRpcInteropLite.cs @@ -1280,9 +1280,7 @@ namespace Google.ProtocolBuffers.TestProtos { #endregion #region Services - [global::System.Runtime.InteropServices.GuidAttribute("a65f0925-fd11-4f94-b166-89ac4f027205")] public partial interface ISearchService { - [global::System.Runtime.InteropServices.DispId(5)] global::Google.ProtocolBuffers.TestProtos.SearchResponse Search(global::Google.ProtocolBuffers.TestProtos.SearchRequest searchRequest); global::Google.ProtocolBuffers.TestProtos.SearchResponse RefineSearch(global::Google.ProtocolBuffers.TestProtos.RefineSearchRequest refineSearchRequest); } -- cgit v1.2.3