FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UnityConfiguration/src/UnityConfiguration/TypeExtensions.cs at master · pofman/UnityConfiguration · GitHub
pofman
/
UnityConfiguration
Public
forked from
thedersen/UnityConfiguration
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
UnityConfiguration
/
src
/
UnityConfiguration
/
TypeExtensions.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (46 loc) · 1.7 KB
Breadcrumbs
UnityConfiguration
/
src
/
UnityConfiguration
/
TypeExtensions.cs
Copy path
File metadata and controls
58 lines (46 loc) · 1.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using
System
;
using
System
.
Linq
;
namespace
UnityConfiguration
{
public
static
class
TypeExtensions
{
public
static
bool
IsConcrete
(
this
Type
type
)
{
return
!
type
.
IsAbstract
&&
!
type
.
IsInterface
;
}
public
static
bool
CanBeCreated
(
this
Type
type
)
{
return
type
.
IsConcrete
(
)
&&
type
.
GetConstructors
(
)
.
Length
>
0
;
}
public
static
bool
CanBeCastTo
(
this
Type
typeFrom
,
Type
typeTo
)
{
if
(
typeFrom
==
null
)
return
false
;
if
(
typeFrom
.
IsInterface
||
typeFrom
.
IsAbstract
)
return
false
;
if
(
IsOpenGeneric
(
typeFrom
)
)
return
false
;
return
typeTo
.
IsAssignableFrom
(
typeFrom
)
;
}
public
static
bool
IsOpenGeneric
(
this
Type
type
)
{
return
type
.
IsGenericTypeDefinition
||
type
.
ContainsGenericParameters
;
}
public
static
bool
IsInNamespace
(
this
Type
type
,
string
@namespace
)
{
if
(
type
.
Namespace
!=
null
)
return
type
.
Namespace
.
StartsWith
(
@namespace
)
;
return
false
;
}
public
static
bool
ImplementsInterface
(
this
Type
type
,
Type
implements
)
{
return
implements
.
IsInterface
&&
type
.
GetInterface
(
implements
.
Name
)
!=
null
;
}
public
static
bool
ImplementsInterfaceTemplate
(
this
Type
type
,
Type
templateType
)
{
if
(
!
type
.
IsConcrete
(
)
)
return
false
;
return
type
.
GetInterfaces
(
)
.
Any
(
interfaceType
=>
interfaceType
.
IsGenericType
&&
interfaceType
.
GetGenericTypeDefinition
(
)
==
templateType
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL