diff options
Diffstat (limited to 'src/ProtocolBuffers.Serialization/AbstractReader.cs')
-rw-r--r-- | src/ProtocolBuffers.Serialization/AbstractReader.cs | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/ProtocolBuffers.Serialization/AbstractReader.cs b/src/ProtocolBuffers.Serialization/AbstractReader.cs index c8dfd2b4..e198d0b0 100644 --- a/src/ProtocolBuffers.Serialization/AbstractReader.cs +++ b/src/ProtocolBuffers.Serialization/AbstractReader.cs @@ -469,23 +469,12 @@ namespace Google.ProtocolBuffers.Serialization rawValue = null;
if (ReadEnum(ref rawValue))
{
- if (Enum.IsDefined(typeof(T), rawValue))
+ if (!EnumParser<T>.TryConvert(rawValue, ref value))
{
- if (rawValue is int)
- {
- value = (T) rawValue;
- }
- else if (rawValue is string)
- {
- value = (T) Enum.Parse(typeof(T), (string) rawValue, false);
- }
- else
- {
- value = default(T);
- return false;
- }
- return true;
+ value = default(T);
+ return false;
}
+ return true;
}
return false;
}
@@ -560,13 +549,10 @@ namespace Google.ProtocolBuffers.Serialization {
foreach (object rawValue in array)
{
- if (rawValue is int)
- {
- list.Add((T) rawValue);
- }
- else if (rawValue is string)
+ T val = default(T);
+ if (EnumParser<T>.TryConvert(rawValue, ref val))
{
- list.Add((T) Enum.Parse(typeof(T), (string) rawValue, false));
+ list.Add(val);
}
else
{
|