FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/StateSerialization/MaybeMemberInfo.cs at master · quantfns/pythonnet · GitHub
quantfns
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
StateSerialization
/
MaybeMemberInfo.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (111 loc) · 3.95 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
StateSerialization
/
MaybeMemberInfo.cs
Copy path
File metadata and controls
123 lines (111 loc) · 3.95 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
using
System
;
using
System
.
Reflection
;
using
System
.
Runtime
.
Serialization
;
namespace
Python
.
Runtime
{
[
Serializable
]
internal
struct
MaybeMemberInfo
<
T
>
:
ISerializable
where
T
:
MemberInfo
{
// .ToString() of the serialized object
const
string
SerializationDescription
=
"d"
;
// The ReflectedType of the object
const
string
SerializationType
=
"t"
;
const
string
SerializationMemberName
=
"n"
;
readonly
MemberInfo
?
info
;
[
NonSerialized
]
readonly
Exception
?
deserializationException
;
public
string
DeletedMessage
{
get
{
return
$
"The .NET
{
typeof
(
T
)
.
Name
}
{
Description
}
no longer exists. Cause: "
+
deserializationException
?
.
Message
;
}
}
public
T
Value
{
get
{
if
(
info
==
null
)
{
throw
new
SerializationException
(
DeletedMessage
,
innerException
:
deserializationException
)
;
}
return
(
T
)
info
;
}
}
public
string
Description
{
get
;
}
public
bool
Valid
=>
info
!=
null
;
public
override
string
ToString
(
)
{
return
(
info
!=
null
?
info
.
ToString
(
)
:
$
"missing:
{
Description
}
"
)
;
}
public
MaybeMemberInfo
(
T
fi
)
{
info
=
fi
;
Description
=
info
.
ToString
(
)
;
if
(
info
.
DeclaringType
is
not
null
)
Description
+=
" of "
+
info
.
DeclaringType
;
deserializationException
=
null
;
}
internal
MaybeMemberInfo
(
SerializationInfo
serializationInfo
,
StreamingContext
context
)
{
Description
=
serializationInfo
.
GetString
(
SerializationDescription
)
;
info
=
null
;
deserializationException
=
null
;
try
{
var
tp
=
Type
.
GetType
(
serializationInfo
.
GetString
(
SerializationType
)
)
;
if
(
tp
!=
null
)
{
var
memberName
=
serializationInfo
.
GetString
(
SerializationMemberName
)
;
MemberInfo
?
mi
=
Get
(
tp
,
memberName
,
ClassManager
.
BindingFlags
)
;
if
(
mi
!=
null
&&
ShouldBindMember
(
mi
)
)
{
info
=
mi
;
}
}
}
catch
(
Exception
e
)
{
deserializationException
=
e
;
}
}
static
MemberInfo
?
Get
(
Type
type
,
string
name
,
BindingFlags
flags
)
{
if
(
typeof
(
T
)
==
typeof
(
FieldInfo
)
)
return
type
.
GetField
(
name
,
flags
)
;
if
(
typeof
(
T
)
==
typeof
(
PropertyInfo
)
)
return
type
.
GetProperty
(
name
,
flags
)
;
throw
new
NotImplementedException
(
typeof
(
T
)
.
Name
)
;
}
// This is complicated because we bind fields
// based on the visibility of the field, properties
// based on it's setter/getter (which is a method
// info) visibility and events based on their
// AddMethod visibility.
static
bool
ShouldBindMember
(
MemberInfo
mi
)
{
if
(
mi
is
PropertyInfo
pi
)
{
return
ClassManager
.
ShouldBindProperty
(
pi
)
;
}
else
if
(
mi
is
FieldInfo
fi
)
{
return
ClassManager
.
ShouldBindField
(
fi
)
;
}
else
if
(
mi
is
EventInfo
ei
)
{
return
ClassManager
.
ShouldBindEvent
(
ei
)
;
}
return
false
;
}
public
void
GetObjectData
(
SerializationInfo
serializationInfo
,
StreamingContext
context
)
{
serializationInfo
.
AddValue
(
SerializationDescription
,
Description
)
;
if
(
info
is
not
null
)
{
serializationInfo
.
AddValue
(
SerializationMemberName
,
info
.
Name
)
;
serializationInfo
.
AddValue
(
SerializationType
,
info
.
ReflectedType
.
AssemblyQualifiedName
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL