diff options
author | Jon Skeet <jonskeet@google.com> | 2016-07-08 18:21:25 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2016-07-08 18:21:25 +0100 |
commit | 3df146e198705dee11de890577f004e42126cd70 (patch) | |
tree | a4b23937dcdf49d58966ccd0e8e00d57f4668a68 /csharp/src/Google.Protobuf | |
parent | 8b00675fc855c9943733d27bb3b70fa8ba78ffb3 (diff) | |
download | protobuf-3df146e198705dee11de890577f004e42126cd70.tar.gz protobuf-3df146e198705dee11de890577f004e42126cd70.tar.bz2 protobuf-3df146e198705dee11de890577f004e42126cd70.zip |
Remove unnecessary reflection call
This is the only call to TypeExtensions.IsValueType, so we can remove
that method, making the whole type conditionally compiled out for .NET 3.5
Diffstat (limited to 'csharp/src/Google.Protobuf')
-rw-r--r-- | csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs | 17 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/FieldCodec.cs | 3 |
2 files changed, 4 insertions, 16 deletions
diff --git a/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs b/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs index fe9cda8d..2d93183b 100644 --- a/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs +++ b/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs @@ -33,6 +33,7 @@ using System; using System.Reflection; +#if !DOTNET35 namespace Google.Protobuf.Compatibility { /// <summary> @@ -46,20 +47,6 @@ namespace Google.Protobuf.Compatibility internal static class TypeExtensions { /// <summary> - /// Returns true if the target type is a value type, including a nullable value type or an enum, or false - /// if it's a reference type (class, delegate, interface - including System.ValueType and System.Enum). - /// </summary> -#if DOTNET35 - internal static bool IsValueType(this Type target) { - return target.IsValueType; - } -#else - internal static bool IsValueType(this Type target) - { - return target.GetTypeInfo().IsValueType; - } - - /// <summary> /// See https://msdn.microsoft.com/en-us/library/system.type.isassignablefrom /// </summary> internal static bool IsAssignableFrom(this Type target, Type c) @@ -114,6 +101,6 @@ namespace Google.Protobuf.Compatibility } return null; } -#endif } } +#endif diff --git a/csharp/src/Google.Protobuf/FieldCodec.cs b/csharp/src/Google.Protobuf/FieldCodec.cs index 98313088..c28b47e1 100644 --- a/csharp/src/Google.Protobuf/FieldCodec.cs +++ b/csharp/src/Google.Protobuf/FieldCodec.cs @@ -347,7 +347,8 @@ namespace Google.Protobuf public sealed class FieldCodec<T> { private static readonly T DefaultDefault; - private static readonly bool TypeSupportsPacking = typeof(T).IsValueType() && Nullable.GetUnderlyingType(typeof(T)) == null; + // Only non-nullable value types support packing. This is the simplest way of detecting that. + private static readonly bool TypeSupportsPacking = default(T) != null; static FieldCodec() { |