FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SharpUtils/_Examples.cs at master · IS4Code/SharpUtils · GitHub
IS4Code
/
SharpUtils
Public
Notifications
You must be signed in to change notification settings
Fork
13
Star
83
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
SharpUtils
/
_Examples.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (50 loc) · 1.56 KB
Breadcrumbs
SharpUtils
/
_Examples.cs
Copy path
File metadata and controls
58 lines (50 loc) · 1.56 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
//This code isn't meant to be compiled, it's just a list of examples that I've been lazy to put to their appropriate classes.
#if
false
/* Extended reflection */
var
asb
=
AppDomain
.
CurrentDomain
.
DefineDynamicAssembly
(
new
AssemblyName
(
"TestAsm"
)
,
AssemblyBuilderAccess
.
Save
)
;
var
modb
=
asb
.
DefineDynamicModule
(
"TestAsm.dll"
)
;
var
typ
=
modb
.
DefineType
(
"TestType"
)
;
var
sig
=
new
MethodSignature
(
typeof
(
int
)
.
MakeModifiedType
(
typeof
(
int
[
]
)
)
)
;
var
mb
=
typ
.
DefineMethod
(
"TestMethod"
,
MethodAttributes
.
Public
|
MethodAttributes
.
Static
,
sig
)
;
var
il
=
mb
.
GetILGenerator
(
)
;
il
.
Emit
(
OpCodes
.
Ret
)
;
typ
.
DefineFieldExtended
(
"fld"
,
typeof
(
int
)
.
MakeModifiedType
(
new
SignatureElementType
(
CorElementType
.
Sentinel
)
)
,
FieldAttributes
.
Public
)
;
typ
.
DefineField
(
"fld"
,
typeof
(
int
)
,
null
,
new
[
]
{
typeof
(
int
?
)
}
,
FieldAttributes
.
Public
)
;
typ
.
CreateType
(
)
;
asb
.
Save
(
"TestAsm.dll"
)
;
/* Proxy implementation */
class
MarshalTest
:
MarshalByRefObject
{
public
void
Test
(
int
arg1
,
ref
int
arg2
,
out
int
arg3
)
{
arg3
=
arg1
+
arg2
;
arg2
*=
2
;
}
}
interface
IMarshalInterface
:
IProxyReplacer
<
MarshalTest
,
IMarshalInterface
>
{
void
Test
(
int
arg1
,
ref
int
arg2
,
out
int
arg3
)
;
}
class
MarshalImpl
:
IMarshalInterface
{
public
void
Test
(
int
arg1
,
ref
int
arg2
,
out
int
arg3
)
{
arg3
=
arg1
-
arg2
;
arg2
/=
2
;
}
}
var
pr
=
ProxyImplementationBinder
.
GetProxy
(
new
MarshalImpl
(
)
)
;
int
a
=
10
;
int
b
=
6
;
int
c
;
pr
.
Test
(
a
,
ref
b
,
out
c
)
;
/* Null reference check */
public
static
void
TestRef
(
ref
int
i
)
{
Console
.
WriteLine
(
Reference
.
IsNull
(
ref
i
)
)
;
}
unsafe
{
int
*
a
=
null
;
TestRef
(
ref
*
a
)
;
}
#endif
Back
|
FazBrowse Home
|
New Git URL