Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
4c4db5df
Commit
4c4db5df
authored
Oct 10, 2015
by
Jeremy Meng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GetTypeCode() extension methods for dnxcore50.
parent
02f3c0be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
2 deletions
+50
-2
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+50
-2
No files found.
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
4c4db5df
using
System
;
using
System
;
#if DNXCORE50
using
System.Collections.Generic
;
using
System.Reflection
;
#endif
using
System.Text
;
using
System.Text
;
namespace
StackExchange.Redis
namespace
StackExchange.Redis
...
@@ -606,7 +610,7 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
...
@@ -606,7 +610,7 @@ object IConvertible.ToType(Type conversionType, IFormatProvider provider)
if
(
conversionType
==
null
)
throw
new
ArgumentNullException
(
"conversionType"
);
if
(
conversionType
==
null
)
throw
new
ArgumentNullException
(
"conversionType"
);
if
(
conversionType
==
typeof
(
byte
[]))
return
(
byte
[])
this
;
if
(
conversionType
==
typeof
(
byte
[]))
return
(
byte
[])
this
;
if
(
conversionType
==
typeof
(
RedisValue
))
return
this
;
if
(
conversionType
==
typeof
(
RedisValue
))
return
this
;
switch
(
Type
.
GetTypeCode
(
conversionType
))
switch
(
conversionType
.
GetTypeCode
(
))
{
{
case
TypeCode
.
Boolean
:
return
(
bool
)
this
;
case
TypeCode
.
Boolean
:
return
(
bool
)
this
;
case
TypeCode
.
Byte
:
return
(
byte
)
this
;
case
TypeCode
.
Byte
:
return
(
byte
)
this
;
...
@@ -708,5 +712,49 @@ public bool TryParse(out double val)
...
@@ -708,5 +712,49 @@ public bool TryParse(out double val)
return
TryParseDouble
(
blob
,
out
val
);
return
TryParseDouble
(
blob
,
out
val
);
}
}
}
}
#if DNXCORE50
internal
static
class
ReflectionExtensions
{
internal
static
TypeCode
GetTypeCode
(
this
Type
type
)
{
if
(
type
==
null
)
return
TypeCode
.
Empty
;
TypeCode
result
;
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
result
))
return
result
;
if
(
type
.
GetTypeInfo
().
IsEnum
)
{
type
=
Enum
.
GetUnderlyingType
(
type
);
if
(
typeCodeLookup
.
TryGetValue
(
type
,
out
result
))
return
result
;
}
return
TypeCode
.
Object
;
}
static
readonly
Dictionary
<
Type
,
TypeCode
>
typeCodeLookup
=
new
Dictionary
<
Type
,
TypeCode
>
{
{
typeof
(
bool
),
TypeCode
.
Boolean
},
{
typeof
(
byte
),
TypeCode
.
Byte
},
{
typeof
(
char
),
TypeCode
.
Char
},
{
typeof
(
DateTime
),
TypeCode
.
DateTime
},
{
typeof
(
decimal
),
TypeCode
.
Decimal
},
{
typeof
(
double
),
TypeCode
.
Double
},
{
typeof
(
short
),
TypeCode
.
Int16
},
{
typeof
(
int
),
TypeCode
.
Int32
},
{
typeof
(
long
),
TypeCode
.
Int64
},
{
typeof
(
object
),
TypeCode
.
Object
},
{
typeof
(
sbyte
),
TypeCode
.
SByte
},
{
typeof
(
float
),
TypeCode
.
Single
},
{
typeof
(
string
),
TypeCode
.
String
},
{
typeof
(
ushort
),
TypeCode
.
UInt16
},
{
typeof
(
uint
),
TypeCode
.
UInt32
},
{
typeof
(
ulong
),
TypeCode
.
UInt64
},
};
}
#else
internal
static
TypeCode
GetTypeCode
(
this
Type
type
)
{
return
type
.
GetTypeCode
();
}
#endif
}
}
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