Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
8779cba3
Commit
8779cba3
authored
Jul 09, 2016
by
Jon Skeet
Committed by
GitHub
Jul 09, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1764 from jskeet/remove-is-value-type
Remove unnecessary reflection call
parents
c404c2a2
3df146e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
35 deletions
+6
-35
TypeExtensionsTest.cs
.../Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
+2
-19
TypeExtensions.cs
csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs
+2
-15
FieldCodec.cs
csharp/src/Google.Protobuf/FieldCodec.cs
+2
-1
No files found.
csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
View file @
8779cba3
...
...
@@ -34,6 +34,7 @@ using System;
using
System.Collections.Generic
;
using
System.Reflection
;
#if !DOTNET35
namespace
Google.Protobuf.Compatibility
{
public
class
TypeExtensionsTest
...
...
@@ -50,24 +51,6 @@ namespace Google.Protobuf.Compatibility
{
}
[
Test
]
[
TestCase
(
typeof
(
int
),
true
)]
[
TestCase
(
typeof
(
int
?),
true
)]
[
TestCase
(
typeof
(
Nullable
<>),
true
)]
[
TestCase
(
typeof
(
WireFormat
.
WireType
),
true
)]
[
TestCase
(
typeof
(
string
),
false
)]
[
TestCase
(
typeof
(
object
),
false
)]
[
TestCase
(
typeof
(
Enum
),
false
)]
[
TestCase
(
typeof
(
ValueType
),
false
)]
[
TestCase
(
typeof
(
TypeExtensionsTest
),
false
)]
[
TestCase
(
typeof
(
Action
),
false
)]
[
TestCase
(
typeof
(
Action
<>),
false
)]
[
TestCase
(
typeof
(
IDisposable
),
false
)]
public
void
IsValueType
(
Type
type
,
bool
expected
)
{
Assert
.
AreEqual
(
expected
,
TypeExtensions
.
IsValueType
(
type
));
}
#if !DOTNET35
[
Test
]
[
TestCase
(
typeof
(
object
),
typeof
(
string
),
true
)]
[
TestCase
(
typeof
(
object
),
typeof
(
int
),
true
)]
...
...
@@ -129,6 +112,6 @@ namespace Google.Protobuf.Compatibility
{
Assert
.
Throws
<
AmbiguousMatchException
>(()
=>
TypeExtensions
.
GetMethod
(
type
,
name
));
}
#endif
}
}
#endif
csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs
View file @
8779cba3
...
...
@@ -33,6 +33,7 @@
using
System
;
using
System.Reflection
;
#if !DOTNET35
namespace
Google.Protobuf.Compatibility
{
/// <summary>
...
...
@@ -45,20 +46,6 @@ namespace Google.Protobuf.Compatibility
/// </summary>
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>
...
...
@@ -114,6 +101,6 @@ namespace Google.Protobuf.Compatibility
}
return
null
;
}
#endif
}
}
#endif
csharp/src/Google.Protobuf/FieldCodec.cs
View file @
8779cba3
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment