aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2012-10-14 12:46:10 -0500
committerrogerk <devnull@localhost>2012-10-14 12:46:10 -0500
commit0d91952a584fea498b22fc180fcf599e85fd4933 (patch)
tree63ba2d54acf009baabc987eb2ab958ff5e42f8f5
parent14e011f61ba2f5976f287e67f4ad82e0cdc546cd (diff)
downloadprotobuf-0d91952a584fea498b22fc180fcf599e85fd4933.tar.gz
protobuf-0d91952a584fea498b22fc180fcf599e85fd4933.tar.bz2
protobuf-0d91952a584fea498b22fc180fcf599e85fd4933.zip
Refactoring compatibility code to use FrameworkPortability class
-rw-r--r--src/ProtocolBuffers.Serialization/AbstractReader.cs23
-rw-r--r--src/ProtocolBuffers.Serialization/AbstractTextReader.cs2
-rw-r--r--src/ProtocolBuffers.Serialization/AbstractWriter.cs4
-rw-r--r--src/ProtocolBuffers.Serialization/DictionaryReader.cs2
-rw-r--r--src/ProtocolBuffers.Serialization/JsonTextCursor.cs8
-rw-r--r--src/ProtocolBuffers.Serialization/XmlFormatReader.cs2
-rw-r--r--src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs4
-rw-r--r--src/ProtocolBuffers/Delegates.cs6
-rw-r--r--src/ProtocolBuffers/GeneratedMessageLite.cs2
-rw-r--r--src/ProtocolBuffers/TextFormat.cs12
-rw-r--r--src/ProtocolBuffers/TextTokenizer.cs4
11 files changed, 20 insertions, 49 deletions
diff --git a/src/ProtocolBuffers.Serialization/AbstractReader.cs b/src/ProtocolBuffers.Serialization/AbstractReader.cs
index a46125fc..c8dfd2b4 100644
--- a/src/ProtocolBuffers.Serialization/AbstractReader.cs
+++ b/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
- }
}
} \ No newline at end of file
diff --git a/src/ProtocolBuffers.Serialization/AbstractTextReader.cs b/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
index 3f8a0c05..b40a560a 100644
--- a/src/ProtocolBuffers.Serialization/AbstractTextReader.cs
+++ b/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;
diff --git a/src/ProtocolBuffers.Serialization/AbstractWriter.cs b/src/ProtocolBuffers.Serialization/AbstractWriter.cs
index 1e087ec6..2dc6b887 100644
--- a/src/ProtocolBuffers.Serialization/AbstractWriter.cs
+++ b/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
{
diff --git a/src/ProtocolBuffers.Serialization/DictionaryReader.cs b/src/ProtocolBuffers.Serialization/DictionaryReader.cs
index ac7d2b6f..c460523c 100644
--- a/src/ProtocolBuffers.Serialization/DictionaryReader.cs
+++ b/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
{
diff --git a/src/ProtocolBuffers.Serialization/JsonTextCursor.cs b/src/ProtocolBuffers.Serialization/JsonTextCursor.cs
index 1a798809..19c45af7 100644
--- a/src/ProtocolBuffers.Serialization/JsonTextCursor.cs
+++ b/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);
diff --git a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
index 71ede7d2..a4f111d4 100644
--- a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
+++ b/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;
diff --git a/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs b/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
index 2da0080e..4f4e13d8 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(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
{
diff --git a/src/ProtocolBuffers/Delegates.cs b/src/ProtocolBuffers/Delegates.cs
index 0a7dec07..3b62bc0c 100644
--- a/src/ProtocolBuffers/Delegates.cs
+++ b/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);
} \ No newline at end of file
diff --git a/src/ProtocolBuffers/GeneratedMessageLite.cs b/src/ProtocolBuffers/GeneratedMessageLite.cs
index aecba7d6..0dfc976b 100644
--- a/src/ProtocolBuffers/GeneratedMessageLite.cs
+++ b/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));
}
}
diff --git a/src/ProtocolBuffers/TextFormat.cs b/src/ProtocolBuffers/TextFormat.cs
index bbc76186..c0f4a5f6 100644
--- a/src/ProtocolBuffers/TextFormat.cs
+++ b/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!
diff --git a/src/ProtocolBuffers/TextTokenizer.cs b/src/ProtocolBuffers/TextTokenizer.cs
index 7fdbd1d6..90774bc2 100644
--- a/src/ProtocolBuffers/TextTokenizer.cs
+++ b/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;
}