diff options
author | detlevschwabe <detlev.schwabe@gmail.com> | 2016-06-27 22:31:42 -0700 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2016-06-28 06:31:42 +0100 |
commit | dc0aeaa9030bdac264b44d56d07b6839a1ae94e9 (patch) | |
tree | 4c2fa16988a67942b15307b8da9fd0e1f3994a99 /csharp/src/Google.Protobuf/JsonFormatter.cs | |
parent | 7b5648ca98b6bde2b18db109bdf020944e0b7baa (diff) | |
download | protobuf-dc0aeaa9030bdac264b44d56d07b6839a1ae94e9.tar.gz protobuf-dc0aeaa9030bdac264b44d56d07b6839a1ae94e9.tar.bz2 protobuf-dc0aeaa9030bdac264b44d56d07b6839a1ae94e9.zip |
Adding conditional compiler symbol to support .NET 3.5 (#1713)
* Adding condition compiler symbol to support .NET 3.5
Diffstat (limited to 'csharp/src/Google.Protobuf/JsonFormatter.cs')
-rw-r--r-- | csharp/src/Google.Protobuf/JsonFormatter.cs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 2aa98cd1..a894ffa1 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -885,6 +885,16 @@ namespace Google.Protobuf return originalName; } +#if DOTNET35 + // TODO: Consider adding functionality to TypeExtensions to avoid this difference. + private static Dictionary<object, string> GetNameMapping(System.Type enumType) => + enumType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static) + .ToDictionary(f => f.GetValue(null), + f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false) + .FirstOrDefault() as OriginalNameAttribute) + // If the attribute hasn't been applied, fall back to the name of the field. + ?.Name ?? f.Name); +#else private static Dictionary<object, string> GetNameMapping(System.Type enumType) => enumType.GetTypeInfo().DeclaredFields .Where(f => f.IsStatic) @@ -893,6 +903,7 @@ namespace Google.Protobuf .FirstOrDefault() // If the attribute hasn't been applied, fall back to the name of the field. ?.Name ?? f.Name); +#endif } } } |