FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/genericutil.cs at python3.9 · sdpython/pythonnet · GitHub
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
sdpython
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
genericutil.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
157 lines (142 loc) · 4.3 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
genericutil.cs
Copy path
File metadata and controls
157 lines (142 loc) · 4.3 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Resources
;
namespace
Python
.
Runtime
{
/// <summary>
/// This class is responsible for efficiently maintaining the bits
/// of information we need to support aliases with 'nice names'.
/// </summary>
internal
class
GenericUtil
{
private
static
Dictionary
<
string
,
Dictionary
<
string
,
List
<
string
>
>
>
mapping
;
private
GenericUtil
(
)
{
}
public
static
void
Reset
(
)
{
mapping
=
new
Dictionary
<
string
,
Dictionary
<
string
,
List
<
string
>
>
>
(
)
;
}
/// <summary>
/// Register a generic type that appears in a given namespace.
/// </summary>
internal
static
void
Register
(
Type
t
)
{
if
(
null
==
t
.
Namespace
||
null
==
t
.
Name
)
{
return
;
}
Dictionary
<
string
,
List
<
string
>
>
nsmap
=
null
;
mapping
.
TryGetValue
(
t
.
Namespace
,
out
nsmap
)
;
if
(
nsmap
==
null
)
{
nsmap
=
new
Dictionary
<
string
,
List
<
string
>
>
(
)
;
mapping
[
t
.
Namespace
]
=
nsmap
;
}
string
basename
=
t
.
Name
;
int
tick
=
basename
.
IndexOf
(
"`"
)
;
if
(
tick
>
-
1
)
{
basename
=
basename
.
Substring
(
0
,
tick
)
;
}
List
<
string
>
gnames
=
null
;
nsmap
.
TryGetValue
(
basename
,
out
gnames
)
;
if
(
gnames
==
null
)
{
gnames
=
new
List
<
string
>
(
)
;
nsmap
[
basename
]
=
gnames
;
}
gnames
.
Add
(
t
.
Name
)
;
}
/// <summary>
/// xxx
/// </summary>
public
static
List
<
string
>
GetGenericBaseNames
(
string
ns
)
{
Dictionary
<
string
,
List
<
string
>
>
nsmap
=
null
;
mapping
.
TryGetValue
(
ns
,
out
nsmap
)
;
if
(
nsmap
==
null
)
{
return
null
;
}
var
names
=
new
List
<
string
>
(
)
;
foreach
(
string
key
in
nsmap
.
Keys
)
{
names
.
Add
(
key
)
;
}
return
names
;
}
/// <summary>
/// xxx
/// </summary>
public
static
Type
GenericForType
(
Type
t
,
int
paramCount
)
{
return
GenericByName
(
t
.
Namespace
,
t
.
Name
,
paramCount
)
;
}
public
static
Type
GenericByName
(
string
ns
,
string
name
,
int
paramCount
)
{
foreach
(
Type
t
in
GenericsByName
(
ns
,
name
)
)
{
if
(
t
.
GetGenericArguments
(
)
.
Length
==
paramCount
)
{
return
t
;
}
}
return
null
;
}
public
static
List
<
Type
>
GenericsForType
(
Type
t
)
{
return
GenericsByName
(
t
.
Namespace
,
t
.
Name
)
;
}
public
static
List
<
Type
>
GenericsByName
(
string
ns
,
string
basename
)
{
Dictionary
<
string
,
List
<
string
>
>
nsmap
=
null
;
mapping
.
TryGetValue
(
ns
,
out
nsmap
)
;
if
(
nsmap
==
null
)
{
return
null
;
}
int
tick
=
basename
.
IndexOf
(
"`"
)
;
if
(
tick
>
-
1
)
{
basename
=
basename
.
Substring
(
0
,
tick
)
;
}
List
<
string
>
names
=
null
;
nsmap
.
TryGetValue
(
basename
,
out
names
)
;
if
(
names
==
null
)
{
return
null
;
}
var
result
=
new
List
<
Type
>
(
)
;
foreach
(
string
name
in
names
)
{
string
qname
=
ns
+
"."
+
name
;
Type
o
=
AssemblyManager
.
LookupType
(
qname
)
;
if
(
o
!=
null
)
{
result
.
Add
(
o
)
;
}
}
return
result
;
}
/// <summary>
/// xxx
/// </summary>
public
static
string
GenericNameForBaseName
(
string
ns
,
string
name
)
{
Dictionary
<
string
,
List
<
string
>
>
nsmap
=
null
;
mapping
.
TryGetValue
(
ns
,
out
nsmap
)
;
if
(
nsmap
==
null
)
{
return
null
;
}
List
<
string
>
gnames
=
null
;
nsmap
.
TryGetValue
(
name
,
out
gnames
)
;
if
(
gnames
?
.
Count
>
0
)
{
return
gnames
[
0
]
;
}
return
null
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL