Browse Source

Refactoring compatibility code to use FrameworkPortability class

csharptest 13 years ago
parent
commit
0d91952a58

+ 0 - 23
src/ProtocolBuffers.Serialization/AbstractReader.cs

@@ -698,28 +698,5 @@ namespace Google.ProtocolBuffers.Serialization
         }
 
         #endregion
-
-        internal static bool TryParseInt32(string text, out int number)
-        {
-            return TryParseInt32(text, NumberStyles.Any, CultureInfo.InvariantCulture, out number);
-        }
-
-        internal static bool TryParseInt32(string text, NumberStyles style, IFormatProvider format, out int number)
-        {
-#if COMPACT_FRAMEWORK
-                try 
-                {
-                    number = int.Parse(text, NumberStyles.Integer, CultureInfo.InvariantCulture); 
-                    return true;
-                }
-                catch 
-                {
-                    number = 0;
-                    return false; 
-                }
-#else
-                return int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number);
-#endif
-        }
     }
 }

+ 1 - 1
src/ProtocolBuffers.Serialization/AbstractTextReader.cs

@@ -163,7 +163,7 @@ namespace Google.ProtocolBuffers.Serialization
             if (ReadAsText(ref text, typeof(Enum)))
             {
                 int number;
-                if (TryParseInt32(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out number))
+                if (FrameworkPortability.TryParseInt32(text, NumberStyles.Integer, FrameworkPortability.InvariantCulture, out number))
                 {
                     value = number;
                     return true;

+ 2 - 2
src/ProtocolBuffers.Serialization/AbstractWriter.cs

@@ -157,8 +157,8 @@ namespace Google.ProtocolBuffers.Serialization
                         }
                         else if (value is IConvertible)
                         {
-                            WriteEnum(field, ((IConvertible) value).ToInt32(CultureInfo.InvariantCulture),
-                                      ((IConvertible) value).ToString(CultureInfo.InvariantCulture));
+                            WriteEnum(field, ((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture),
+                                      ((IConvertible)value).ToString(FrameworkPortability.InvariantCulture));
                         }
                         else
                         {

+ 1 - 1
src/ProtocolBuffers.Serialization/DictionaryReader.cs

@@ -82,7 +82,7 @@ namespace Google.ProtocolBuffers.Serialization
                 {
                     if (obj is IConvertible)
                     {
-                        value = (T) Convert.ChangeType(obj, typeof(T), CultureInfo.InvariantCulture);
+                        value = (T)Convert.ChangeType(obj, typeof(T), FrameworkPortability.InvariantCulture);
                     }
                     else
                     {

+ 4 - 4
src/ProtocolBuffers.Serialization/JsonTextCursor.cs

@@ -195,7 +195,7 @@ namespace Google.ProtocolBuffers.Serialization
             if (!cond)
             {
                 throw new FormatException(
-                    String.Format(CultureInfo.InvariantCulture,
+                    String.Format(FrameworkPortability.InvariantCulture,
                                   "({0}:{1}) error: Unexpected token {2}, expected: {3}.",
                                   _lineNo, _linePos,
                                   CharDisplay(_next),
@@ -210,7 +210,7 @@ namespace Google.ProtocolBuffers.Serialization
             if (!cond)
             {
                 throw new FormatException(
-                    String.Format(CultureInfo.InvariantCulture,
+                    String.Format(FrameworkPortability.InvariantCulture,
                                   "({0},{1}) error: {2}", _lineNo, _linePos, message));
             }
         }
@@ -225,7 +225,7 @@ namespace Google.ProtocolBuffers.Serialization
                     format = String.Format(format, args);
                 }
                 throw new FormatException(
-                    String.Format(CultureInfo.InvariantCulture,
+                    String.Format(FrameworkPortability.InvariantCulture,
                                   "({0},{1}) error: {2}", _lineNo, _linePos, format));
             }
         }
@@ -322,7 +322,7 @@ namespace Google.ProtocolBuffers.Serialization
                                 string hex = new string(new char[] {ReadChar(), ReadChar(), ReadChar(), ReadChar()});
                                 int result;
                                 Assert(
-                                    AbstractTextReader.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture,
+                                    FrameworkPortability.TryParseInt32(hex, NumberStyles.AllowHexSpecifier, FrameworkPortability.InvariantCulture,
                                                  out result),
                                     "Expected a 4-character hex specifier.");
                                 sb.Add((char) result);

+ 1 - 1
src/ProtocolBuffers.Serialization/XmlFormatReader.cs

@@ -269,7 +269,7 @@ namespace Google.ProtocolBuffers.Serialization
         {
             int number;
             string temp;
-            if (null != (temp = _input.GetAttribute("value")) && TryParseInt32(temp, out number))
+            if (null != (temp = _input.GetAttribute("value")) && FrameworkPortability.TryParseInt32(temp, out number))
             {
                 Skip();
                 value = number;

+ 2 - 2
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(CultureInfo.InvariantCulture));
+                        return ComputeEnumSize(fieldNumber, ((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture));
                     }
                     else
                     {
@@ -631,7 +631,7 @@ namespace Google.ProtocolBuffers
                 case FieldType.Enum:
                     if (value is Enum)
                     {
-                        return ComputeEnumSizeNoTag(((IConvertible) value).ToInt32(CultureInfo.InvariantCulture));
+                        return ComputeEnumSizeNoTag(((IConvertible)value).ToInt32(FrameworkPortability.InvariantCulture));
                     }
                     else
                     {

+ 0 - 6
src/ProtocolBuffers/Delegates.cs

@@ -50,11 +50,5 @@ namespace Google.ProtocolBuffers
 
     internal delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
 
-    internal delegate TResult Func<T1, T2, T3, TResult>(T1 arg1, T2 arg2, T3 arg3);
-
-    internal delegate TResult Func<T1, T2, T3, T4, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
-
-    internal delegate void Action();
-
     internal delegate void Action<T1, T2>(T1 arg1, T2 arg2);
 }

+ 1 - 1
src/ProtocolBuffers/GeneratedMessageLite.cs

@@ -111,7 +111,7 @@ namespace Google.ProtocolBuffers
             }
             else
             {
-                writer.WriteLine("{0}: {1}", name, ((IConvertible) value).ToString(CultureInfo.InvariantCulture));
+                writer.WriteLine("{0}: {1}", name, ((IConvertible)value).ToString(FrameworkPortability.InvariantCulture));
             }
         }
 

+ 6 - 6
src/ProtocolBuffers/TextFormat.cs

@@ -170,10 +170,10 @@ namespace Google.ProtocolBuffers
                     // the double to/from string will trim the precision to 6 places.  As with other numeric formats
                     // below, always use the invariant culture so it's predictable.
                 case FieldType.Float:
-                    generator.Print(((float) value).ToString("r", CultureInfo.InvariantCulture));
+                    generator.Print(((float)value).ToString("r", FrameworkPortability.InvariantCulture));
                     break;
                 case FieldType.Double:
-                    generator.Print(((double) value).ToString("r", CultureInfo.InvariantCulture));
+                    generator.Print(((double)value).ToString("r", FrameworkPortability.InvariantCulture));
                     break;
 
                 case FieldType.Int32:
@@ -188,7 +188,7 @@ namespace Google.ProtocolBuffers
                 case FieldType.Fixed64:
                     // The simple Object.ToString converts using the current culture.
                     // We want to always use the invariant culture so it's predictable.
-                    generator.Print(((IConvertible) value).ToString(CultureInfo.InvariantCulture));
+                    generator.Print(((IConvertible)value).ToString(FrameworkPortability.InvariantCulture));
                     break;
                 case FieldType.Bool:
                     // Explicitly use the Java true/false
@@ -314,7 +314,7 @@ namespace Google.ProtocolBuffers
                 case "nanf":
                     return float.NaN;
                 default:
-                    return float.Parse(text, CultureInfo.InvariantCulture);
+                    return float.Parse(text, FrameworkPortability.InvariantCulture);
             }
         }
 
@@ -331,7 +331,7 @@ namespace Google.ProtocolBuffers
                 case "nan":
                     return double.NaN;
                 default:
-                    return double.Parse(text, CultureInfo.InvariantCulture);
+                    return double.Parse(text, FrameworkPortability.InvariantCulture);
             }
         }
 
@@ -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(CultureInfo.InvariantCulture);
+                    String lowerName = name.ToLower(FrameworkPortability.InvariantCulture);
                     field = type.FindDescriptor<FieldDescriptor>(lowerName);
                     // If the case-insensitive match worked but the field is NOT a group,
                     // TODO(jonskeet): What? Java comment ends here!

+ 2 - 2
src/ProtocolBuffers/TextTokenizer.cs

@@ -346,7 +346,7 @@ namespace Google.ProtocolBuffers
 
             try
             {
-                double result = double.Parse(currentToken, CultureInfo.InvariantCulture);
+                double result = double.Parse(currentToken, FrameworkPortability.InvariantCulture);
                 NextToken();
                 return result;
             }
@@ -387,7 +387,7 @@ namespace Google.ProtocolBuffers
 
             try
             {
-                float result = float.Parse(currentToken, CultureInfo.InvariantCulture);
+                float result = float.Parse(currentToken, FrameworkPortability.InvariantCulture);
                 NextToken();
                 return result;
             }