99 changed files with 6701 additions and 127 deletions
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
bin |
||||
obj |
||||
*.suo |
||||
*.user |
||||
*.pidb |
||||
*.userprefs |
||||
*.xml |
||||
*.nupkg |
||||
**/test-results/* |
||||
*Resharper* |
||||
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
<NUnitProject> |
||||
<Settings activeconfig="Default" /> |
||||
<Config name="Default" binpathtype="Auto"> |
||||
<assembly path="Test\bin\net_4_0_Debug\Mono.Cecil.Tests.dll" /> |
||||
<assembly path="rocks\Test\bin\net_4_0_Debug\Mono.Cecil.Rocks.Tests.dll" /> |
||||
<assembly path="symbols\mdb\Test\bin\net_4_0_Debug\Mono.Cecil.Mdb.Tests.dll" /> |
||||
<assembly path="symbols\pdb\Test\bin\net_4_0_Debug\Mono.Cecil.Pdb.Tests.dll" /> |
||||
</Config> |
||||
</NUnitProject> |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?> |
||||
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
||||
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> |
||||
<id>Mono.Cecil</id> |
||||
<version>0.9.5.0</version> |
||||
<title>Mono.Cecil</title> |
||||
<authors>Jb Evain</authors> |
||||
<owners>Jb Evain</owners> |
||||
<licenseUrl>http://opensource.org/licenses/mit-license.php</licenseUrl> |
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance> |
||||
<projectUrl>http://github.com/jbevain/cecil/</projectUrl> |
||||
<summary>Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format.</summary> |
||||
<description>Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. It has full support for generics, and support some debugging symbol format. In simple English, with Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly.</description> |
||||
<language>en-US</language> |
||||
<tags>assembly assemblies module modules il cil msil bytecode reflection injection cecil mono aop</tags> |
||||
</metadata> |
||||
<files> |
||||
<file src="bin\net_2_0_Release\*.dll" target="lib/net20" /> |
||||
<file src="bin\net_3_5_Release\*.dll" target="lib/net35" /> |
||||
<file src="bin\net_4_0_Release\*.dll" target="lib/net40" /> |
||||
<file src="bin\silverlight_Release\*.dll" target="lib/sl40" /> |
||||
</files> |
||||
</package> |
||||
@ -0,0 +1,197 @@
@@ -0,0 +1,197 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00 |
||||
# Visual Studio 2010 |
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{74E5ECE0-06B4-401C-AEBA-E8DD53E17943}" |
||||
EndProject |
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Symbols", "Symbols", "{929D5B3B-E29A-40CC-93D8-0FF43A6F9FA1}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Tests", "Test\Mono.Cecil.Tests.csproj", "{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dbg", "dbg\dbg.csproj", "{89A775F3-64AB-485E-B958-60C25254B732}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Mdb", "symbols\mdb\Mono.Cecil.Mdb.csproj", "{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Mdb.Tests", "symbols\mdb\Test\Mono.Cecil.Mdb.Tests.csproj", "{AC71DF9C-99FA-4A63-990A-66C8010355A6}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "symbols\pdb\Mono.Cecil.Pdb.csproj", "{63E6915C-7EA4-4D76-AB28-0D7191EEA626}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb.Tests", "symbols\pdb\Test\Mono.Cecil.Pdb.Tests.csproj", "{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks.Tests", "rocks\Test\Mono.Cecil.Rocks.Tests.csproj", "{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks", "rocks\Mono.Cecil.Rocks.csproj", "{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
net_2_0_Debug|Any CPU = net_2_0_Debug|Any CPU |
||||
net_2_0_Release|Any CPU = net_2_0_Release|Any CPU |
||||
net_3_5_Debug|Any CPU = net_3_5_Debug|Any CPU |
||||
net_3_5_Release|Any CPU = net_3_5_Release|Any CPU |
||||
net_4_0_Debug|Any CPU = net_4_0_Debug|Any CPU |
||||
net_4_0_Release|Any CPU = net_4_0_Release|Any CPU |
||||
silverlight_Debug|Any CPU = silverlight_Debug|Any CPU |
||||
silverlight_Release|Any CPU = silverlight_Release|Any CPU |
||||
winphone_Debug|Any CPU = winphone_Debug|Any CPU |
||||
winphone_Release|Any CPU = winphone_Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.silverlight_Debug|Any CPU.ActiveCfg = silverlight_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.silverlight_Debug|Any CPU.Build.0 = silverlight_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.silverlight_Release|Any CPU.ActiveCfg = silverlight_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.silverlight_Release|Any CPU.Build.0 = silverlight_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.winphone_Debug|Any CPU.ActiveCfg = winphone_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.winphone_Debug|Any CPU.Build.0 = winphone_Debug|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.winphone_Release|Any CPU.ActiveCfg = winphone_Release|Any CPU |
||||
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.winphone_Release|Any CPU.Build.0 = winphone_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_2_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_2_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{89A775F3-64AB-485E-B958-60C25254B732}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_2_0_Debug|Any CPU.ActiveCfg = net_2_0_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_2_0_Debug|Any CPU.Build.0 = net_2_0_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_2_0_Release|Any CPU.ActiveCfg = net_2_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_2_0_Release|Any CPU.Build.0 = net_2_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_2_0_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_2_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.silverlight_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.silverlight_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.winphone_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.winphone_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_2_0_Debug|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_2_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug|Any CPU.Build.0 = net_3_5_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Release|Any CPU.Build.0 = net_3_5_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_0_Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_0_Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.silverlight_Debug|Any CPU.ActiveCfg = silverlight_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.silverlight_Debug|Any CPU.Build.0 = silverlight_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.silverlight_Release|Any CPU.ActiveCfg = silverlight_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.silverlight_Release|Any CPU.Build.0 = silverlight_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.winphone_Debug|Any CPU.ActiveCfg = winphone_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.winphone_Debug|Any CPU.Build.0 = winphone_Debug|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.winphone_Release|Any CPU.ActiveCfg = winphone_Release|Any CPU |
||||
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.winphone_Release|Any CPU.Build.0 = winphone_Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(SolutionProperties) = preSolution |
||||
HideSolutionNode = FALSE |
||||
EndGlobalSection |
||||
GlobalSection(NestedProjects) = preSolution |
||||
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943} |
||||
{AC71DF9C-99FA-4A63-990A-66C8010355A6} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943} |
||||
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943} |
||||
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943} |
||||
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD} = {929D5B3B-E29A-40CC-93D8-0FF43A6F9FA1} |
||||
{63E6915C-7EA4-4D76-AB28-0D7191EEA626} = {929D5B3B-E29A-40CC-93D8-0FF43A6F9FA1} |
||||
EndGlobalSection |
||||
EndGlobal |
||||
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
bin |
||||
obj |
||||
*.suo |
||||
*.user |
||||
*.xml |
||||
*.pidb |
||||
*.userprefs |
||||
@ -0,0 +1,178 @@
@@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>9.0.30729</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>Mono.Cecil.Tests</RootNamespace> |
||||
<AssemblyName>Mono.Cecil.Tests</AssemblyName> |
||||
<FileAlignment>512</FileAlignment> |
||||
<SignAssembly>true</SignAssembly> |
||||
<AssemblyOriginatorKeyFile>..\mono.snk</AssemblyOriginatorKeyFile> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\net_2_0_Debug\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\net_2_0_Release\</OutputPath> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\net_3_5_Debug\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE;NET_3_5</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\net_3_5_Release\</OutputPath> |
||||
<DefineConstants>TRACE;NET_3_5</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\net_4_0_Debug\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE;NET_3_5;NET_4_0</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\net_4_0_Release\</OutputPath> |
||||
<DefineConstants>TRACE;NET_3_5;NET_4_0</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' "> |
||||
<Reference Include="System.Core" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
<HintPath>libs\nunit-2.4.8\nunit.core.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="nunit.core.interfaces, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
<HintPath>libs\nunit-2.4.8\nunit.core.interfaces.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
<HintPath>libs\nunit-2.4.8\nunit.framework.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Mono.Cecil.Tests\Addin.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\AssemblyTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\AssemblyInfo.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\BaseTestFixture.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\CompilationService.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\VariableTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\TypeParserTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ImportCecilTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ImportReflectionTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ILProcessorTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\SecurityDeclarationTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ParameterTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\Extensions.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\Linq.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ResolveTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\CustomAttributesTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\Formatter.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\MethodBodyTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\TypeTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\PropertyTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\EventTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\MethodTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\FieldTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ImageReadTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\ModuleTests.cs" /> |
||||
<Compile Include="Mono.Cecil.Tests\NestedTypesTests.cs" /> |
||||
<None Include="Resources\cs\CustomAttributes.cs" /> |
||||
<None Include="Resources\cs\Generics.cs" /> |
||||
<None Include="Resources\cs\Interfaces.cs" /> |
||||
<None Include="Resources\cs\Layouts.cs" /> |
||||
<None Include="Resources\cs\Properties.cs" /> |
||||
<None Include="Resources\cs\Events.cs" /> |
||||
<None Include="Resources\cs\Methods.cs" /> |
||||
<None Include="Resources\assemblies\moda.netmodule" /> |
||||
<None Include="Resources\assemblies\modb.netmodule" /> |
||||
<None Include="Resources\cs\Fields.cs" /> |
||||
<None Include="Resources\cs\NestedTypes.cs" /> |
||||
<None Include="Resources\il\hello.il" /> |
||||
<None Include="Resources\il\methodspecs.il" /> |
||||
<None Include="Resources\il\others.il" /> |
||||
<None Include="Resources\il\types.il" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\Mono.Cecil.csproj"> |
||||
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project> |
||||
<Name>Mono.Cecil</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Content Include="Resources\assemblies\boxedoptarg.dll" /> |
||||
<Content Include="Resources\assemblies\catch.exe" /> |
||||
<Content Include="Resources\assemblies\cppcli.dll" /> |
||||
<Content Include="Resources\assemblies\cscgpbug.dll" /> |
||||
<Content Include="Resources\assemblies\decsec-att.dll" /> |
||||
<Content Include="Resources\assemblies\decsec-xml.dll" /> |
||||
<Content Include="Resources\assemblies\decsec1-xml.dll" /> |
||||
<Content Include="Resources\assemblies\empty-decsec-att.dll" /> |
||||
<Content Include="Resources\assemblies\fptr.exe" /> |
||||
<Content Include="Resources\assemblies\gifaceref.exe" /> |
||||
<Content Include="Resources\assemblies\hello.anycpu.exe" /> |
||||
<Content Include="Resources\assemblies\hello.exe" /> |
||||
<Content Include="Resources\assemblies\hello.ia64.exe" /> |
||||
<Content Include="Resources\assemblies\hello.x64.exe" /> |
||||
<Content Include="Resources\assemblies\hello.x86.exe" /> |
||||
<Content Include="Resources\assemblies\hello1.exe" /> |
||||
<Content Include="Resources\assemblies\hellow.exe" /> |
||||
<Content Include="Resources\assemblies\iterator.exe" /> |
||||
<Content Include="Resources\assemblies\libhello.dll" /> |
||||
<Content Include="Resources\assemblies\libres.dll" /> |
||||
<Content Include="Resources\assemblies\marshal.dll" /> |
||||
<Content Include="Resources\assemblies\mma.exe" /> |
||||
<Content Include="Resources\assemblies\noblob.dll" /> |
||||
<Content Include="Resources\assemblies\pinvoke.exe" /> |
||||
<Content Include="Resources\assemblies\switch.exe" /> |
||||
<Content Include="Resources\assemblies\text_file.txt" /> |
||||
<Content Include="Resources\assemblies\varargs.exe" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
||||
@ -0,0 +1,303 @@
@@ -0,0 +1,303 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
|
||||
using NUnit.Core; |
||||
using NUnit.Core.Extensibility; |
||||
|
||||
using Mono.Cecil.Cil; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
public abstract class TestCecilAttribute : Attribute { |
||||
|
||||
bool verify = true; |
||||
Type symbol_reader_provider; |
||||
Type symbol_writer_provider; |
||||
|
||||
public bool Verify { |
||||
get { return verify; } |
||||
set { verify = value; } |
||||
} |
||||
|
||||
public Type SymbolReaderProvider { |
||||
get { return symbol_reader_provider; } |
||||
set { symbol_reader_provider = value; } |
||||
} |
||||
|
||||
public Type SymbolWriterProvider { |
||||
get { return symbol_writer_provider; } |
||||
set { symbol_writer_provider = value; } |
||||
} |
||||
|
||||
public abstract string GetModuleLocation (Assembly assembly); |
||||
} |
||||
|
||||
[AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] |
||||
public sealed class TestModuleAttribute : TestCecilAttribute { |
||||
|
||||
readonly string module; |
||||
|
||||
public string Module { |
||||
get { return module; } |
||||
} |
||||
|
||||
public TestModuleAttribute (string assembly) |
||||
{ |
||||
this.module = assembly; |
||||
} |
||||
|
||||
public override string GetModuleLocation (Assembly assembly) |
||||
{ |
||||
return BaseTestFixture.GetAssemblyResourcePath (module, assembly); |
||||
} |
||||
} |
||||
|
||||
[AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] |
||||
public sealed class TestCSharpAttribute : TestCecilAttribute { |
||||
|
||||
readonly string file; |
||||
|
||||
public string File { |
||||
get { return file; } |
||||
} |
||||
|
||||
public TestCSharpAttribute (string file) |
||||
{ |
||||
this.file = file; |
||||
} |
||||
|
||||
public override string GetModuleLocation (Assembly assembly) |
||||
{ |
||||
return CompilationService.CompileResource ( |
||||
BaseTestFixture.GetCSharpResourcePath (file, assembly)); |
||||
} |
||||
} |
||||
|
||||
[AttributeUsage (AttributeTargets.Method, AllowMultiple = false)] |
||||
public sealed class TestILAttribute : TestCecilAttribute { |
||||
|
||||
readonly string file; |
||||
|
||||
public string File { |
||||
get { return file; } |
||||
} |
||||
|
||||
public TestILAttribute (string file) |
||||
{ |
||||
this.file = file; |
||||
} |
||||
|
||||
public override string GetModuleLocation (Assembly assembly) |
||||
{ |
||||
return CompilationService.CompileResource ( |
||||
BaseTestFixture.GetILResourcePath (file, assembly)); |
||||
} |
||||
} |
||||
|
||||
class CecilTestCase : NUnitTestMethod { |
||||
|
||||
readonly TestCecilAttribute attribute; |
||||
readonly TestCaseType type; |
||||
|
||||
public CecilTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type) |
||||
: base (method) |
||||
{ |
||||
this.TestName.Name = type.ToString (); |
||||
this.TestName.FullName = method.DeclaringType.FullName + "." + method.Name + "." + type; |
||||
this.attribute = attribute; |
||||
this.type = type; |
||||
} |
||||
|
||||
ModuleDefinition GetModule () |
||||
{ |
||||
var location = attribute.GetModuleLocation (this.Method.DeclaringType.Assembly); |
||||
|
||||
var parameters = new ReaderParameters { |
||||
SymbolReaderProvider = GetSymbolReaderProvider (attribute), |
||||
}; |
||||
|
||||
switch (type) { |
||||
case TestCaseType.ReadImmediate: |
||||
parameters.ReadingMode = ReadingMode.Immediate; |
||||
return ModuleDefinition.ReadModule (location, parameters); |
||||
case TestCaseType.ReadDeferred: |
||||
parameters.ReadingMode = ReadingMode.Deferred; |
||||
return ModuleDefinition.ReadModule (location, parameters); |
||||
case TestCaseType.WriteFromImmediate: |
||||
parameters.ReadingMode = ReadingMode.Immediate; |
||||
return RoundTrip (location, parameters, "cecil-irt"); |
||||
case TestCaseType.WriteFromDeferred: |
||||
parameters.ReadingMode = ReadingMode.Deferred; |
||||
return RoundTrip (location, parameters, "cecil-drt"); |
||||
default: |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
static ISymbolReaderProvider GetSymbolReaderProvider (TestCecilAttribute attribute) |
||||
{ |
||||
if (attribute.SymbolReaderProvider == null) |
||||
return null; |
||||
|
||||
return (ISymbolReaderProvider) Activator.CreateInstance (attribute.SymbolReaderProvider); |
||||
} |
||||
|
||||
static ISymbolWriterProvider GetSymbolWriterProvider (TestCecilAttribute attribute) |
||||
{ |
||||
if (attribute.SymbolReaderProvider == null) |
||||
return null; |
||||
|
||||
return (ISymbolWriterProvider) Activator.CreateInstance (attribute.SymbolWriterProvider); |
||||
} |
||||
|
||||
ModuleDefinition RoundTrip (string location, ReaderParameters reader_parameters, string folder) |
||||
{ |
||||
var module = ModuleDefinition.ReadModule (location, reader_parameters); |
||||
var rt_folder = Path.Combine (Path.GetTempPath (), folder); |
||||
if (!Directory.Exists (rt_folder)) |
||||
Directory.CreateDirectory (rt_folder); |
||||
var rt_module = Path.Combine (rt_folder, Path.GetFileName (location)); |
||||
|
||||
var writer_parameters = new WriterParameters { |
||||
SymbolWriterProvider = GetSymbolWriterProvider (attribute), |
||||
}; |
||||
|
||||
Reflect.InvokeMethod (Method, Fixture, new object [] { module }); |
||||
|
||||
module.Write (rt_module, writer_parameters); |
||||
|
||||
if (attribute.Verify) |
||||
CompilationService.Verify (rt_module); |
||||
|
||||
return ModuleDefinition.ReadModule (rt_module, reader_parameters); |
||||
} |
||||
|
||||
public override void RunTestMethod (TestCaseResult testResult) |
||||
{ |
||||
var module = GetModule (); |
||||
if (module == null) |
||||
return; |
||||
|
||||
Reflect.InvokeMethod (Method, Fixture, new object [] { module }); |
||||
|
||||
testResult.Success (); |
||||
} |
||||
} |
||||
|
||||
class CecilTestSuite : TestSuite { |
||||
|
||||
public CecilTestSuite (MethodInfo method) |
||||
: base (method.DeclaringType.FullName, method.Name) |
||||
{ |
||||
} |
||||
|
||||
public override TestResult Run (EventListener listener, ITestFilter filter) |
||||
{ |
||||
if (this.Parent != null) |
||||
this.Fixture = this.Parent.Fixture; |
||||
|
||||
return base.Run (listener, filter); |
||||
} |
||||
|
||||
protected override void DoOneTimeSetUp (TestResult suiteResult) |
||||
{ |
||||
} |
||||
|
||||
protected override void DoOneTimeTearDown (TestResult suiteResult) |
||||
{ |
||||
} |
||||
} |
||||
|
||||
enum TestCaseType { |
||||
ReadImmediate, |
||||
ReadDeferred, |
||||
WriteFromImmediate, |
||||
WriteFromDeferred, |
||||
} |
||||
|
||||
static class CecilTestFactory { |
||||
|
||||
public static CecilTestSuite CreateTestSuite (MethodInfo method) |
||||
{ |
||||
if (method == null) |
||||
throw new ArgumentNullException ("method"); |
||||
|
||||
var suite = new CecilTestSuite (method); |
||||
|
||||
NUnitFramework.ApplyCommonAttributes (method, suite); |
||||
PopulateTestSuite (method, suite); |
||||
|
||||
return suite; |
||||
} |
||||
|
||||
static void PopulateTestSuite (MethodInfo method, CecilTestSuite suite) |
||||
{ |
||||
var attribute = GetTestCecilAttribute (method); |
||||
if (attribute == null) |
||||
throw new ArgumentException (); |
||||
|
||||
foreach (var value in Enum.GetValues (typeof (TestCaseType))) { |
||||
var test = CreateTestCase (method, attribute, (TestCaseType) value); |
||||
if (test != null) |
||||
suite.Add (test); |
||||
} |
||||
} |
||||
|
||||
static CecilTestCase CreateTestCase (MethodInfo method, TestCecilAttribute attribute, TestCaseType type) |
||||
{ |
||||
return new CecilTestCase (method, attribute, type); |
||||
} |
||||
|
||||
static TestCecilAttribute GetTestCecilAttribute (MethodInfo method) |
||||
{ |
||||
foreach (var attribute in method.GetCustomAttributes (false)) { |
||||
var test = attribute as TestCecilAttribute; |
||||
if (test != null) |
||||
return test; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
|
||||
[NUnitAddin] |
||||
public class CecilTestAddin : IAddin, ITestCaseBuilder { |
||||
|
||||
public bool Install (IExtensionHost host) |
||||
{ |
||||
if (host == null) |
||||
throw new ArgumentNullException ("host"); |
||||
|
||||
var builders = host.GetExtensionPoint ("TestCaseBuilders"); |
||||
if (builders == null) |
||||
return false; |
||||
|
||||
builders.Install (this); |
||||
return true; |
||||
} |
||||
|
||||
public Test BuildFrom (MethodInfo method) |
||||
{ |
||||
if (method == null) |
||||
throw new ArgumentNullException ("method"); |
||||
|
||||
return CecilTestFactory.CreateTestSuite (method); |
||||
} |
||||
|
||||
public bool CanBuildFrom (MethodInfo method) |
||||
{ |
||||
if (method == null) |
||||
return false; |
||||
|
||||
return IsCecilTestMethod (method); |
||||
} |
||||
|
||||
static bool IsCecilTestMethod (MethodInfo method) |
||||
{ |
||||
return Reflect.HasAttribute (method, typeof (TestModuleAttribute).FullName, false) |
||||
|| Reflect.HasAttribute (method, typeof (TestILAttribute).FullName, false) |
||||
|| Reflect.HasAttribute (method, typeof (TestCSharpAttribute).FullName, false); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
[assembly: AssemblyTitle ("Mono.Cecil.Tests")] |
||||
[assembly: AssemblyProduct ("Mono.Cecil")] |
||||
[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")] |
||||
|
||||
[assembly: ComVisible (false)] |
||||
|
||||
[assembly: Guid ("da96c202-696a-457e-89af-5fa74e6bda0d")] |
||||
|
||||
[assembly: AssemblyVersion ("1.0.0.0")] |
||||
[assembly: AssemblyFileVersion ("1.0.0.0")] |
||||
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
using System; |
||||
|
||||
using Mono.Cecil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class AssemblyTests : BaseTestFixture { |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void Name (ModuleDefinition module) |
||||
{ |
||||
var name = module.Assembly.Name; |
||||
|
||||
Assert.IsNotNull (name); |
||||
|
||||
Assert.AreEqual ("hello", name.Name); |
||||
Assert.AreEqual (string.Empty, name.Culture); |
||||
Assert.AreEqual (new Version (0, 0, 0, 0), name.Version); |
||||
Assert.AreEqual (AssemblyHashAlgorithm.SHA1, name.HashAlgorithm); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
using Mono.Cecil.PE; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
public abstract class BaseTestFixture { |
||||
|
||||
public static string GetResourcePath (string name, Assembly assembly) |
||||
{ |
||||
return Path.Combine (FindResourcesDirectory (assembly), name); |
||||
} |
||||
|
||||
public static string GetAssemblyResourcePath (string name, Assembly assembly) |
||||
{ |
||||
return GetResourcePath (Path.Combine ("assemblies", name), assembly); |
||||
} |
||||
|
||||
public static string GetCSharpResourcePath (string name, Assembly assembly) |
||||
{ |
||||
return GetResourcePath (Path.Combine ("cs", name), assembly); |
||||
} |
||||
|
||||
public static string GetILResourcePath (string name, Assembly assembly) |
||||
{ |
||||
return GetResourcePath (Path.Combine ("il", name), assembly); |
||||
} |
||||
|
||||
public static ModuleDefinition GetResourceModule (string name) |
||||
{ |
||||
return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly)); |
||||
} |
||||
|
||||
public static ModuleDefinition GetResourceModule (string name, ReaderParameters parameters) |
||||
{ |
||||
return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), parameters); |
||||
} |
||||
|
||||
public static ModuleDefinition GetResourceModule (string name, ReadingMode mode) |
||||
{ |
||||
return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), new ReaderParameters (mode)); |
||||
} |
||||
|
||||
internal static Image GetResourceImage (string name) |
||||
{ |
||||
using (var fs = new FileStream (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), FileMode.Open, FileAccess.Read)) |
||||
return ImageReader.ReadImageFrom (fs); |
||||
} |
||||
|
||||
public static ModuleDefinition GetCurrentModule () |
||||
{ |
||||
return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName); |
||||
} |
||||
|
||||
public static ModuleDefinition GetCurrentModule (ReaderParameters parameters) |
||||
{ |
||||
return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName, parameters); |
||||
} |
||||
|
||||
public static string FindResourcesDirectory (Assembly assembly) |
||||
{ |
||||
var path = Path.GetDirectoryName (new Uri (assembly.CodeBase).LocalPath); |
||||
while (!Directory.Exists (Path.Combine (path, "Resources"))) { |
||||
var old = path; |
||||
path = Path.GetDirectoryName (path); |
||||
Assert.AreNotEqual (old, path); |
||||
} |
||||
|
||||
return Path.Combine (path, "Resources"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,237 @@
@@ -0,0 +1,237 @@
|
||||
using System; |
||||
using System.CodeDom.Compiler; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
struct CompilationResult { |
||||
internal DateTime source_write_time; |
||||
internal string result_file; |
||||
|
||||
public CompilationResult (DateTime write_time, string result_file) |
||||
{ |
||||
this.source_write_time = write_time; |
||||
this.result_file = result_file; |
||||
} |
||||
} |
||||
|
||||
abstract class CompilationService { |
||||
|
||||
Dictionary<string, CompilationResult> files = new Dictionary<string, CompilationResult> (); |
||||
|
||||
bool TryGetResult (string name, out string file_result) |
||||
{ |
||||
file_result = null; |
||||
CompilationResult result; |
||||
if (!files.TryGetValue (name, out result)) |
||||
return false; |
||||
|
||||
if (result.source_write_time != File.GetLastWriteTime (name)) |
||||
return false; |
||||
|
||||
file_result = result.result_file; |
||||
return true; |
||||
} |
||||
|
||||
public string Compile (string name) |
||||
{ |
||||
string result_file; |
||||
if (TryGetResult (name, out result_file)) |
||||
return result_file; |
||||
|
||||
result_file = CompileFile (name); |
||||
RegisterFile (name, result_file); |
||||
return result_file; |
||||
} |
||||
|
||||
void RegisterFile (string name, string result_file) |
||||
{ |
||||
files [name] = new CompilationResult (File.GetLastWriteTime (name), result_file); |
||||
} |
||||
|
||||
protected abstract string CompileFile (string name); |
||||
|
||||
public static string CompileResource (string name) |
||||
{ |
||||
var extension = Path.GetExtension (name); |
||||
if (extension == ".il") |
||||
return IlasmCompilationService.Instance.Compile (name); |
||||
|
||||
if (extension == ".cs" || extension == ".vb") |
||||
return CodeDomCompilationService.Instance.Compile (name); |
||||
|
||||
throw new NotSupportedException (extension); |
||||
} |
||||
|
||||
protected static string GetCompiledFilePath (string file_name) |
||||
{ |
||||
var tmp_cecil = Path.Combine (Path.GetTempPath (), "cecil"); |
||||
if (!Directory.Exists (tmp_cecil)) |
||||
Directory.CreateDirectory (tmp_cecil); |
||||
|
||||
return Path.Combine (tmp_cecil, Path.GetFileName (file_name) + ".dll"); |
||||
} |
||||
|
||||
static bool OnMono { get { return typeof (object).Assembly.GetType ("Mono.Runtime") != null; } } |
||||
|
||||
public static void Verify (string name) |
||||
{ |
||||
var output = OnMono ? ShellService.PEDump (name) : ShellService.PEVerify (name); |
||||
if (output.ExitCode != 0) |
||||
Assert.Fail (output.ToString ()); |
||||
} |
||||
} |
||||
|
||||
class IlasmCompilationService : CompilationService { |
||||
|
||||
public static readonly IlasmCompilationService Instance = new IlasmCompilationService (); |
||||
|
||||
protected override string CompileFile (string name) |
||||
{ |
||||
string file = GetCompiledFilePath (name); |
||||
|
||||
var output = ShellService.ILAsm (name, file); |
||||
|
||||
AssertAssemblerResult (output); |
||||
|
||||
return file; |
||||
} |
||||
|
||||
static void AssertAssemblerResult (ShellService.ProcessOutput output) |
||||
{ |
||||
if (output.ExitCode != 0) |
||||
Assert.Fail (output.ToString ()); |
||||
} |
||||
} |
||||
|
||||
class CodeDomCompilationService : CompilationService { |
||||
|
||||
public static readonly CodeDomCompilationService Instance = new CodeDomCompilationService (); |
||||
|
||||
protected override string CompileFile (string name) |
||||
{ |
||||
string file = GetCompiledFilePath (name); |
||||
|
||||
using (var provider = GetProvider (name)) { |
||||
var parameters = GetDefaultParameters (name); |
||||
parameters.IncludeDebugInformation = false; |
||||
parameters.GenerateExecutable = false; |
||||
parameters.OutputAssembly = file; |
||||
|
||||
var results = provider.CompileAssemblyFromFile (parameters, name); |
||||
AssertCompilerResults (results); |
||||
} |
||||
|
||||
return file; |
||||
} |
||||
|
||||
static void AssertCompilerResults (CompilerResults results) |
||||
{ |
||||
Assert.IsFalse (results.Errors.HasErrors, GetErrorMessage (results)); |
||||
} |
||||
|
||||
static string GetErrorMessage (CompilerResults results) |
||||
{ |
||||
if (!results.Errors.HasErrors) |
||||
return string.Empty; |
||||
|
||||
var builder = new StringBuilder (); |
||||
foreach (CompilerError error in results.Errors) |
||||
builder.AppendLine (error.ToString ()); |
||||
return builder.ToString (); |
||||
} |
||||
|
||||
static CompilerParameters GetDefaultParameters (string name) |
||||
{ |
||||
return GetCompilerInfo (name).CreateDefaultCompilerParameters (); |
||||
} |
||||
|
||||
static CodeDomProvider GetProvider (string name) |
||||
{ |
||||
return GetCompilerInfo (name).CreateProvider (); |
||||
} |
||||
|
||||
static CompilerInfo GetCompilerInfo (string name) |
||||
{ |
||||
return CodeDomProvider.GetCompilerInfo ( |
||||
CodeDomProvider.GetLanguageFromExtension (Path.GetExtension (name))); |
||||
} |
||||
} |
||||
|
||||
class ShellService { |
||||
|
||||
public class ProcessOutput { |
||||
|
||||
public int ExitCode; |
||||
public string StdOut; |
||||
public string StdErr; |
||||
|
||||
public ProcessOutput (int exitCode, string stdout, string stderr) |
||||
{ |
||||
ExitCode = exitCode; |
||||
StdOut = stdout; |
||||
StdErr = stderr; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return StdOut + StdErr; |
||||
} |
||||
} |
||||
|
||||
static ProcessOutput RunProcess (string target, params string [] arguments) |
||||
{ |
||||
var stdout = new StringWriter (); |
||||
var stderr = new StringWriter (); |
||||
|
||||
var process = new Process { |
||||
StartInfo = new ProcessStartInfo { |
||||
FileName = target, |
||||
Arguments = string.Join (" ", arguments), |
||||
CreateNoWindow = true, |
||||
UseShellExecute = false, |
||||
RedirectStandardError = true, |
||||
RedirectStandardInput = true, |
||||
RedirectStandardOutput = true, |
||||
}, |
||||
}; |
||||
|
||||
process.Start (); |
||||
|
||||
process.OutputDataReceived += (_, args) => stdout.Write (args.Data); |
||||
process.ErrorDataReceived += (_, args) => stderr.Write (args.Data); |
||||
|
||||
process.BeginOutputReadLine (); |
||||
process.BeginErrorReadLine (); |
||||
|
||||
process.WaitForExit (); |
||||
|
||||
return new ProcessOutput (process.ExitCode, stdout.ToString (), stderr.ToString ()); |
||||
} |
||||
|
||||
public static ProcessOutput ILAsm (string source, string output) |
||||
{ |
||||
return RunProcess ("ilasm", "/nologo", "/dll", "/out:" + Quote (output), Quote (source)); |
||||
} |
||||
|
||||
static string Quote (string file) |
||||
{ |
||||
return "\"" + file + "\""; |
||||
} |
||||
|
||||
public static ProcessOutput PEVerify (string source) |
||||
{ |
||||
return RunProcess ("peverify", "/nologo", Quote (source)); |
||||
} |
||||
|
||||
public static ProcessOutput PEDump (string source) |
||||
{ |
||||
return RunProcess ("pedump", "--verify code,metadata", Quote (source)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,511 @@
@@ -0,0 +1,511 @@
|
||||
using System; |
||||
using System.Globalization; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
using Mono.Cecil.PE; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class CustomAttributesTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void StringArgumentOnType (ModuleDefinition module) |
||||
{ |
||||
var hamster = module.GetType ("Hamster"); |
||||
|
||||
Assert.IsTrue (hamster.HasCustomAttributes); |
||||
Assert.AreEqual (1, hamster.CustomAttributes.Count); |
||||
|
||||
var attribute = hamster.CustomAttributes [0]; |
||||
Assert.AreEqual ("System.Void FooAttribute::.ctor(System.String)", |
||||
attribute.Constructor.FullName); |
||||
|
||||
Assert.IsTrue (attribute.HasConstructorArguments); |
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
AssertArgument ("bar", attribute.ConstructorArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void NullString (ModuleDefinition module) |
||||
{ |
||||
var dentist = module.GetType ("Dentist"); |
||||
|
||||
var attribute = GetAttribute (dentist, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
AssertArgument<string> (null, attribute.ConstructorArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void Primitives1 (ModuleDefinition module) |
||||
{ |
||||
var steven = module.GetType ("Steven"); |
||||
|
||||
var attribute = GetAttribute (steven, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
AssertArgument<sbyte> (-12, attribute.ConstructorArguments [0]); |
||||
AssertArgument<byte> (242, attribute.ConstructorArguments [1]); |
||||
AssertArgument<bool> (true, attribute.ConstructorArguments [2]); |
||||
AssertArgument<bool> (false, attribute.ConstructorArguments [3]); |
||||
AssertArgument<ushort> (4242, attribute.ConstructorArguments [4]); |
||||
AssertArgument<short> (-1983, attribute.ConstructorArguments [5]); |
||||
AssertArgument<char> ('c', attribute.ConstructorArguments [6]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void Primitives2 (ModuleDefinition module) |
||||
{ |
||||
var seagull = module.GetType ("Seagull"); |
||||
|
||||
var attribute = GetAttribute (seagull, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
AssertArgument<int> (-100000, attribute.ConstructorArguments [0]); |
||||
AssertArgument<uint> (200000, attribute.ConstructorArguments [1]); |
||||
AssertArgument<float> (12.12f, attribute.ConstructorArguments [2]); |
||||
AssertArgument<long> (long.MaxValue, attribute.ConstructorArguments [3]); |
||||
AssertArgument<ulong> (ulong.MaxValue, attribute.ConstructorArguments [4]); |
||||
AssertArgument<double> (64.646464, attribute.ConstructorArguments [5]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void StringArgumentOnAssembly (ModuleDefinition module) |
||||
{ |
||||
var assembly = module.Assembly; |
||||
|
||||
var attribute = GetAttribute (assembly, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
AssertArgument ("bingo", attribute.ConstructorArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void CharArray (ModuleDefinition module) |
||||
{ |
||||
var rifle = module.GetType ("Rifle"); |
||||
|
||||
var attribute = GetAttribute (rifle, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
Assert.AreEqual ("System.Char[]", argument.Type.FullName); |
||||
|
||||
var array = argument.Value as CustomAttributeArgument []; |
||||
Assert.IsNotNull (array); |
||||
|
||||
var str = "cecil"; |
||||
|
||||
Assert.AreEqual (array.Length, str.Length); |
||||
|
||||
for (int i = 0; i < str.Length; i++) |
||||
AssertArgument (str [i], array [i]); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void BoxedArguments (ModuleDefinition module) |
||||
{ |
||||
var worm = module.GetType ("Worm"); |
||||
|
||||
var attribute = GetAttribute (worm, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (".ctor ((Object:(String:\"2\")), (Object:(I4:2)))", PrettyPrint (attribute)); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void BoxedArraysArguments (ModuleDefinition module) |
||||
{ |
||||
var sheep = module.GetType ("Sheep"); |
||||
|
||||
var attribute = GetAttribute (sheep, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
// [Foo (new object [] { "2", 2, 'c' }, new object [] { new object [] { 1, 2, 3}, null })]
|
||||
AssertCustomAttribute (".ctor ((Object:(Object[]:{(Object:(String:\"2\")), (Object:(I4:2)), (Object:(Char:'c'))})), (Object:(Object[]:{(Object:(Object[]:{(Object:(I4:1)), (Object:(I4:2)), (Object:(I4:3))})), (Object:(String:null))})))", attribute); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void FieldsAndProperties (ModuleDefinition module) |
||||
{ |
||||
var angola = module.GetType ("Angola"); |
||||
|
||||
var attribute = GetAttribute (angola, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (2, attribute.Fields.Count); |
||||
|
||||
var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); |
||||
AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(I4:1)), (Object:(String:\"2\")), (Object:(Char:'3'))}))", argument); |
||||
|
||||
argument = attribute.Fields.Where (a => a.Name == "PanPan").First (); |
||||
AssertCustomAttributeArgument ("(String[]:{(String:\"yo\"), (String:\"yo\")})", argument); |
||||
|
||||
Assert.AreEqual (2, attribute.Properties.Count); |
||||
|
||||
argument = attribute.Properties.Where (a => a.Name == "Bang").First (); |
||||
AssertArgument (42, argument); |
||||
|
||||
argument = attribute.Properties.Where (a => a.Name == "Fiou").First (); |
||||
AssertArgument<string> (null, argument); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void BoxedStringField (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("BoxedStringField"); |
||||
|
||||
var attribute = GetAttribute (type, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.Fields.Count); |
||||
|
||||
var argument = attribute.Fields.Where (a => a.Name == "Pan").First (); |
||||
AssertCustomAttributeArgument ("(Object:(String:\"fiouuu\"))", argument); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void TypeDefinitionEnum (ModuleDefinition module) |
||||
{ |
||||
var zero = module.GetType ("Zero"); |
||||
|
||||
var attribute = GetAttribute (zero, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
Assert.AreEqual ((short) 2, attribute.ConstructorArguments [0].Value); |
||||
Assert.AreEqual ("Bingo", attribute.ConstructorArguments [0].Type.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void TypeReferenceEnum (ModuleDefinition module) |
||||
{ |
||||
var ace = module.GetType ("Ace"); |
||||
|
||||
var attribute = GetAttribute (ace, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
Assert.AreEqual ((byte) 0x04, attribute.ConstructorArguments [0].Value); |
||||
Assert.AreEqual ("System.Security.AccessControl.AceFlags", attribute.ConstructorArguments [0].Type.FullName); |
||||
Assert.AreEqual (module, attribute.ConstructorArguments [0].Type.Module); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void BoxedEnumReference (ModuleDefinition module) |
||||
{ |
||||
var bzzz = module.GetType ("Bzzz"); |
||||
|
||||
var attribute = GetAttribute (bzzz, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
// [Foo (new object [] { Bingo.Fuel, Bingo.Binga }, null, Pan = System.Security.AccessControl.AceFlags.NoPropagateInherit)]
|
||||
|
||||
Assert.AreEqual (2, attribute.ConstructorArguments.Count); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
AssertCustomAttributeArgument ("(Object:(Object[]:{(Object:(Bingo:2)), (Object:(Bingo:4))}))", argument); |
||||
|
||||
argument = attribute.ConstructorArguments [1]; |
||||
|
||||
AssertCustomAttributeArgument ("(Object:(String:null))", argument); |
||||
|
||||
argument = attribute.Fields.Where (a => a.Name == "Pan").First ().Argument; |
||||
|
||||
AssertCustomAttributeArgument ("(Object:(System.Security.AccessControl.AceFlags:4))", argument); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void TypeOfTypeDefinition (ModuleDefinition module) |
||||
{ |
||||
var typed = module.GetType ("Typed"); |
||||
|
||||
var attribute = GetAttribute (typed, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
var type = argument.Value as TypeDefinition; |
||||
Assert.IsNotNull (type); |
||||
|
||||
Assert.AreEqual ("Bingo", type.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void TypeOfNestedTypeDefinition (ModuleDefinition module) |
||||
{ |
||||
var typed = module.GetType ("NestedTyped"); |
||||
|
||||
var attribute = GetAttribute (typed, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
var type = argument.Value as TypeDefinition; |
||||
Assert.IsNotNull (type); |
||||
|
||||
Assert.AreEqual ("FooAttribute/Token", type.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void FieldTypeOf (ModuleDefinition module) |
||||
{ |
||||
var truc = module.GetType ("Truc"); |
||||
|
||||
var attribute = GetAttribute (truc, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
var type = argument.Value as TypeDefinition; |
||||
Assert.IsNotNull (type); |
||||
|
||||
Assert.AreEqual ("Typed", type.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void FieldNullTypeOf (ModuleDefinition module) |
||||
{ |
||||
var truc = module.GetType ("Machin"); |
||||
|
||||
var attribute = GetAttribute (truc, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
var argument = attribute.Fields.Where (a => a.Name == "Chose").First ().Argument; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
Assert.IsNull (argument.Value); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void OpenGenericTypeOf (ModuleDefinition module) |
||||
{ |
||||
var open_generic = module.GetType ("OpenGeneric`2"); |
||||
Assert.IsNotNull (open_generic); |
||||
|
||||
var attribute = GetAttribute (open_generic, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
var type = argument.Value as TypeReference; |
||||
Assert.IsNotNull (type); |
||||
|
||||
Assert.AreEqual ("System.Collections.Generic.Dictionary`2", type.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void ClosedGenericTypeOf (ModuleDefinition module) |
||||
{ |
||||
var closed_generic = module.GetType ("ClosedGeneric"); |
||||
Assert.IsNotNull (closed_generic); |
||||
|
||||
var attribute = GetAttribute (closed_generic, "Foo"); |
||||
Assert.IsNotNull (attribute); |
||||
|
||||
Assert.AreEqual (1, attribute.ConstructorArguments.Count); |
||||
|
||||
var argument = attribute.ConstructorArguments [0]; |
||||
|
||||
Assert.AreEqual ("System.Type", argument.Type.FullName); |
||||
|
||||
var type = argument.Value as TypeReference; |
||||
Assert.IsNotNull (type); |
||||
|
||||
Assert.AreEqual ("System.Collections.Generic.Dictionary`2<System.String,OpenGeneric`2<Machin,System.Int32>[,]>", type.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefineCustomAttributeFromBlob () |
||||
{ |
||||
var file = Path.Combine (Path.GetTempPath (), "CaBlob.dll"); |
||||
|
||||
var module = ModuleDefinition.CreateModule ("CaBlob.dll", new ModuleParameters { Kind = ModuleKind.Dll, Runtime = TargetRuntime.Net_2_0 }); |
||||
var assembly_title_ctor = module.Import (typeof (System.Reflection.AssemblyTitleAttribute).GetConstructor (new [] {typeof (string)})); |
||||
|
||||
Assert.IsNotNull (assembly_title_ctor); |
||||
|
||||
var buffer = new ByteBuffer (); |
||||
buffer.WriteUInt16 (1); // ca signature
|
||||
|
||||
var title = Encoding.UTF8.GetBytes ("CaBlob"); |
||||
|
||||
buffer.WriteCompressedUInt32 ((uint) title.Length); |
||||
buffer.WriteBytes (title); |
||||
|
||||
buffer.WriteUInt16 (0); // named arguments
|
||||
|
||||
var blob = new byte [buffer.length]; |
||||
Buffer.BlockCopy (buffer.buffer, 0, blob, 0, buffer.length); |
||||
|
||||
var attribute = new CustomAttribute (assembly_title_ctor, blob); |
||||
module.Assembly.CustomAttributes.Add (attribute); |
||||
|
||||
module.Write (file); |
||||
|
||||
module = ModuleDefinition.ReadModule (file); |
||||
|
||||
attribute = GetAttribute (module.Assembly, "AssemblyTitle"); |
||||
|
||||
Assert.IsNotNull (attribute); |
||||
Assert.AreEqual ("CaBlob", (string) attribute.ConstructorArguments [0].Value); |
||||
} |
||||
|
||||
static void AssertCustomAttribute (string expected, CustomAttribute attribute) |
||||
{ |
||||
Assert.AreEqual (expected, PrettyPrint (attribute)); |
||||
} |
||||
|
||||
static void AssertCustomAttributeArgument (string expected, CustomAttributeNamedArgument named_argument) |
||||
{ |
||||
AssertCustomAttributeArgument (expected, named_argument.Argument); |
||||
} |
||||
|
||||
static void AssertCustomAttributeArgument (string expected, CustomAttributeArgument argument) |
||||
{ |
||||
var result = new StringBuilder (); |
||||
PrettyPrint (argument, result); |
||||
|
||||
Assert.AreEqual (expected, result.ToString ()); |
||||
} |
||||
|
||||
static string PrettyPrint (CustomAttribute attribute) |
||||
{ |
||||
var signature = new StringBuilder (); |
||||
signature.Append (".ctor ("); |
||||
|
||||
for (int i = 0; i < attribute.ConstructorArguments.Count; i++) { |
||||
if (i > 0) |
||||
signature.Append (", "); |
||||
|
||||
PrettyPrint (attribute.ConstructorArguments [i], signature); |
||||
} |
||||
|
||||
signature.Append (")"); |
||||
return signature.ToString (); |
||||
} |
||||
|
||||
static void PrettyPrint (CustomAttributeArgument argument, StringBuilder signature) |
||||
{ |
||||
var value = argument.Value; |
||||
|
||||
signature.Append ("("); |
||||
|
||||
PrettyPrint (argument.Type, signature); |
||||
|
||||
signature.Append (":"); |
||||
|
||||
PrettyPrintValue (argument.Value, signature); |
||||
|
||||
signature.Append (")"); |
||||
} |
||||
|
||||
static void PrettyPrintValue (object value, StringBuilder signature) |
||||
{ |
||||
if (value == null) { |
||||
signature.Append ("null"); |
||||
return; |
||||
} |
||||
|
||||
var arguments = value as CustomAttributeArgument []; |
||||
if (arguments != null) { |
||||
signature.Append ("{"); |
||||
for (int i = 0; i < arguments.Length; i++) { |
||||
if (i > 0) |
||||
signature.Append (", "); |
||||
|
||||
PrettyPrint (arguments [i], signature); |
||||
} |
||||
signature.Append ("}"); |
||||
|
||||
return; |
||||
} |
||||
|
||||
switch (Type.GetTypeCode (value.GetType ())) { |
||||
case TypeCode.String: |
||||
signature.AppendFormat ("\"{0}\"", value); |
||||
break; |
||||
case TypeCode.Char: |
||||
signature.AppendFormat ("'{0}'", (char) value); |
||||
break; |
||||
default: |
||||
var formattable = value as IFormattable; |
||||
if (formattable != null) { |
||||
signature.Append (formattable.ToString (null, CultureInfo.InvariantCulture)); |
||||
return; |
||||
} |
||||
|
||||
if (value is CustomAttributeArgument) { |
||||
PrettyPrint ((CustomAttributeArgument) value, signature); |
||||
return; |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static void PrettyPrint (TypeReference type, StringBuilder signature) |
||||
{ |
||||
if (type.IsArray) { |
||||
ArrayType array = (ArrayType) type; |
||||
signature.AppendFormat ("{0}[]", array.ElementType.etype.ToString ()); |
||||
} else if (type.etype == ElementType.None) { |
||||
signature.Append (type.FullName); |
||||
} else |
||||
signature.Append (type.etype.ToString ()); |
||||
} |
||||
|
||||
static void AssertArgument<T> (T value, CustomAttributeNamedArgument named_argument) |
||||
{ |
||||
AssertArgument (value, named_argument.Argument); |
||||
} |
||||
|
||||
static void AssertArgument<T> (T value, CustomAttributeArgument argument) |
||||
{ |
||||
AssertArgument (typeof (T).FullName, (object) value, argument); |
||||
} |
||||
|
||||
static void AssertArgument (string type, object value, CustomAttributeArgument argument) |
||||
{ |
||||
Assert.AreEqual (type, argument.Type.FullName); |
||||
Assert.AreEqual (value, argument.Value); |
||||
} |
||||
|
||||
static CustomAttribute GetAttribute (ICustomAttributeProvider owner, string type) |
||||
{ |
||||
Assert.IsTrue (owner.HasCustomAttributes); |
||||
|
||||
foreach (var attribute in owner.CustomAttributes) |
||||
if (attribute.Constructor.DeclaringType.Name.StartsWith (type)) |
||||
return attribute; |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
using System; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class EventTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("Events.cs")] |
||||
public void AbstractMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Foo"); |
||||
|
||||
Assert.IsTrue (type.HasEvents); |
||||
|
||||
var events = type.Events; |
||||
|
||||
Assert.AreEqual (1, events.Count); |
||||
|
||||
var @event = events [0]; |
||||
|
||||
Assert.IsNotNull (@event); |
||||
Assert.AreEqual ("Bar", @event.Name); |
||||
Assert.IsNotNull (@event.EventType); |
||||
Assert.AreEqual ("Pan", @event.EventType.FullName); |
||||
|
||||
Assert.IsNotNull (@event.AddMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.AddOn, @event.AddMethod.SemanticsAttributes); |
||||
Assert.IsNotNull (@event.RemoveMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.RemoveOn, @event.RemoveMethod.SemanticsAttributes); |
||||
} |
||||
|
||||
[TestIL ("others.il")] |
||||
public void OtherMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Others"); |
||||
|
||||
Assert.IsTrue (type.HasEvents); |
||||
|
||||
var events = type.Events; |
||||
|
||||
Assert.AreEqual (1, events.Count); |
||||
|
||||
var @event = events [0]; |
||||
|
||||
Assert.IsNotNull (@event); |
||||
Assert.AreEqual ("Handler", @event.Name); |
||||
Assert.IsNotNull (@event.EventType); |
||||
Assert.AreEqual ("System.EventHandler", @event.EventType.FullName); |
||||
|
||||
Assert.IsTrue (@event.HasOtherMethods); |
||||
|
||||
Assert.AreEqual (2, @event.OtherMethods.Count); |
||||
|
||||
var other = @event.OtherMethods [0]; |
||||
Assert.AreEqual ("dang_Handler", other.Name); |
||||
|
||||
other = @event.OtherMethods [1]; |
||||
Assert.AreEqual ("fang_Handler", other.Name); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
using System; |
||||
using System.Linq; |
||||
using SR = System.Reflection; |
||||
|
||||
using Mono.Cecil; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
public static class Extensions { |
||||
|
||||
public static MethodDefinition GetMethod (this TypeDefinition self, string name) |
||||
{ |
||||
return self.Methods.Where (m => m.Name == name).First (); |
||||
} |
||||
|
||||
public static FieldDefinition GetField (this TypeDefinition self, string name) |
||||
{ |
||||
return self.Fields.Where (f => f.Name == name).First (); |
||||
} |
||||
|
||||
public static TypeDefinition ToDefinition (this Type self) |
||||
{ |
||||
var module = ModuleDefinition.ReadModule (self.Module.FullyQualifiedName); |
||||
return (TypeDefinition) module.LookupToken (self.MetadataToken); |
||||
} |
||||
|
||||
public static MethodDefinition ToDefinition (this SR.MethodBase method) |
||||
{ |
||||
var declaring_type = method.DeclaringType.ToDefinition (); |
||||
return (MethodDefinition) declaring_type.Module.LookupToken (method.MetadataToken); |
||||
} |
||||
|
||||
public static FieldDefinition ToDefinition (this SR.FieldInfo field) |
||||
{ |
||||
var declaring_type = field.DeclaringType.ToDefinition (); |
||||
return (FieldDefinition) declaring_type.Module.LookupToken (field.MetadataToken); |
||||
} |
||||
|
||||
public static TypeReference MakeGenericType (this TypeReference self, params TypeReference [] arguments) |
||||
{ |
||||
if (self.GenericParameters.Count != arguments.Length) |
||||
throw new ArgumentException (); |
||||
|
||||
var instance = new GenericInstanceType (self); |
||||
foreach (var argument in arguments) |
||||
instance.GenericArguments.Add (argument); |
||||
|
||||
return instance; |
||||
} |
||||
|
||||
public static MethodReference MakeGenericMethod (this MethodReference self, params TypeReference [] arguments) |
||||
{ |
||||
if (self.GenericParameters.Count != arguments.Length) |
||||
throw new ArgumentException (); |
||||
|
||||
var instance = new GenericInstanceMethod (self); |
||||
foreach (var argument in arguments) |
||||
instance.GenericArguments.Add (argument); |
||||
|
||||
return instance; |
||||
} |
||||
|
||||
public static MethodReference MakeGeneric (this MethodReference self, params TypeReference [] arguments) |
||||
{ |
||||
var reference = new MethodReference { |
||||
Name = self.Name, |
||||
DeclaringType = self.DeclaringType.MakeGenericType (arguments), |
||||
HasThis = self.HasThis, |
||||
ExplicitThis = self.ExplicitThis, |
||||
ReturnType = self.ReturnType, |
||||
CallingConvention = self.CallingConvention, |
||||
}; |
||||
|
||||
foreach (var parameter in self.Parameters) |
||||
reference.Parameters.Add (new ParameterDefinition (parameter.ParameterType)); |
||||
|
||||
foreach (var generic_parameter in self.GenericParameters) |
||||
reference.GenericParameters.Add (new GenericParameter (generic_parameter.Name, reference)); |
||||
|
||||
return reference; |
||||
} |
||||
|
||||
public static FieldReference MakeGeneric (this FieldReference self, params TypeReference [] arguments) |
||||
{ |
||||
return new FieldReference { |
||||
Name = self.Name, |
||||
DeclaringType = self.DeclaringType.MakeGenericType (arguments), |
||||
FieldType = self.FieldType, |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,333 @@
@@ -0,0 +1,333 @@
|
||||
using System; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
using Mono.Cecil.PE; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class FieldTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void TypeDefField (ModuleDefinition module) |
||||
{ |
||||
var type = module.Types [1]; |
||||
Assert.AreEqual ("Foo", type.Name); |
||||
Assert.AreEqual (1, type.Fields.Count); |
||||
|
||||
var field = type.Fields [0]; |
||||
Assert.AreEqual ("bar", field.Name); |
||||
Assert.AreEqual (1, field.MetadataToken.RID); |
||||
Assert.IsNotNull (field.FieldType); |
||||
Assert.AreEqual ("Bar", field.FieldType.FullName); |
||||
Assert.AreEqual (TokenType.Field, field.MetadataToken.TokenType); |
||||
Assert.IsFalse (field.HasConstant); |
||||
Assert.IsNull (field.Constant); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void PrimitiveTypes (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Baz"); |
||||
|
||||
AssertField (type, "char", typeof (char)); |
||||
AssertField (type, "bool", typeof (bool)); |
||||
AssertField (type, "sbyte", typeof (sbyte)); |
||||
AssertField (type, "byte", typeof (byte)); |
||||
AssertField (type, "int16", typeof (short)); |
||||
AssertField (type, "uint16", typeof (ushort)); |
||||
AssertField (type, "int32", typeof (int)); |
||||
AssertField (type, "uint32", typeof (uint)); |
||||
AssertField (type, "int64", typeof (long)); |
||||
AssertField (type, "uint64", typeof (ulong)); |
||||
AssertField (type, "single", typeof (float)); |
||||
AssertField (type, "double", typeof (double)); |
||||
AssertField (type, "string", typeof (string)); |
||||
AssertField (type, "object", typeof (object)); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void VolatileField (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Bar"); |
||||
|
||||
Assert.IsTrue (type.HasFields); |
||||
Assert.AreEqual (1, type.Fields.Count); |
||||
|
||||
var field = type.Fields [0]; |
||||
|
||||
Assert.AreEqual ("oiseau", field.Name); |
||||
Assert.AreEqual ("System.Int32 modreq(System.Runtime.CompilerServices.IsVolatile)", field.FieldType.FullName); |
||||
|
||||
Assert.IsFalse (field.HasConstant); |
||||
} |
||||
|
||||
[TestCSharp ("Layouts.cs")] |
||||
public void FieldLayout (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
Assert.IsNotNull (foo); |
||||
|
||||
Assert.IsTrue (foo.HasFields); |
||||
|
||||
var fields = foo.Fields; |
||||
|
||||
var field = fields [0]; |
||||
|
||||
Assert.AreEqual ("Bar", field.Name); |
||||
Assert.IsTrue (field.HasLayoutInfo); |
||||
Assert.AreEqual (0, field.Offset); |
||||
|
||||
field = fields [1]; |
||||
|
||||
Assert.AreEqual ("Baz", field.Name); |
||||
Assert.IsTrue (field.HasLayoutInfo); |
||||
Assert.AreEqual (2, field.Offset); |
||||
|
||||
field = fields [2]; |
||||
|
||||
Assert.AreEqual ("Gazonk", field.Name); |
||||
Assert.IsTrue (field.HasLayoutInfo); |
||||
Assert.AreEqual (4, field.Offset); |
||||
} |
||||
|
||||
[TestCSharp ("Layouts.cs")] |
||||
public void FieldRVA (ModuleDefinition module) |
||||
{ |
||||
var priv_impl = GetPrivateImplementationType (module); |
||||
Assert.IsNotNull (priv_impl); |
||||
|
||||
Assert.AreEqual (1, priv_impl.Fields.Count); |
||||
|
||||
var field = priv_impl.Fields [0]; |
||||
|
||||
Assert.IsNotNull (field); |
||||
Assert.AreNotEqual (0, field.RVA); |
||||
Assert.IsNotNull (field.InitialValue); |
||||
Assert.AreEqual (16, field.InitialValue.Length); |
||||
|
||||
var buffer = new ByteBuffer (field.InitialValue); |
||||
|
||||
Assert.AreEqual (1, buffer.ReadUInt32 ()); |
||||
Assert.AreEqual (2, buffer.ReadUInt32 ()); |
||||
Assert.AreEqual (3, buffer.ReadUInt32 ()); |
||||
Assert.AreEqual (4, buffer.ReadUInt32 ()); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericFieldDefinition (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar`1"); |
||||
Assert.IsNotNull (bar); |
||||
|
||||
Assert.IsTrue (bar.HasGenericParameters); |
||||
var t = bar.GenericParameters [0]; |
||||
|
||||
Assert.AreEqual ("T", t.Name); |
||||
Assert.AreEqual (t.Owner, bar); |
||||
|
||||
var bang = bar.GetField ("bang"); |
||||
|
||||
Assert.IsNotNull (bang); |
||||
|
||||
Assert.AreEqual (t, bang.FieldType); |
||||
} |
||||
|
||||
[TestIL ("types.il")] |
||||
public void ArrayFields (ModuleDefinition module) |
||||
{ |
||||
var types = module.GetType ("Types"); |
||||
Assert.IsNotNull (types); |
||||
|
||||
var rank_two = types.GetField ("rank_two"); |
||||
|
||||
var array = rank_two.FieldType as ArrayType; |
||||
Assert.IsNotNull (array); |
||||
|
||||
Assert.AreEqual (2, array.Rank); |
||||
Assert.IsFalse (array.Dimensions [0].IsSized); |
||||
Assert.IsFalse (array.Dimensions [1].IsSized); |
||||
|
||||
var rank_two_low_bound_zero = types.GetField ("rank_two_low_bound_zero"); |
||||
|
||||
array = rank_two_low_bound_zero.FieldType as ArrayType; |
||||
Assert.IsNotNull (array); |
||||
|
||||
Assert.AreEqual (2, array.Rank); |
||||
Assert.IsTrue (array.Dimensions [0].IsSized); |
||||
Assert.AreEqual (0, array.Dimensions [0].LowerBound); |
||||
Assert.AreEqual (null, array.Dimensions [0].UpperBound); |
||||
Assert.IsTrue (array.Dimensions [1].IsSized); |
||||
Assert.AreEqual (0, array.Dimensions [1].LowerBound); |
||||
Assert.AreEqual (null, array.Dimensions [1].UpperBound); |
||||
|
||||
var rank_one_low_bound_m1 = types.GetField ("rank_one_low_bound_m1"); |
||||
array = rank_one_low_bound_m1.FieldType as ArrayType; |
||||
Assert.IsNotNull (array); |
||||
|
||||
Assert.AreEqual (1, array.Rank); |
||||
Assert.IsTrue (array.Dimensions [0].IsSized); |
||||
Assert.AreEqual (-1, array.Dimensions [0].LowerBound); |
||||
Assert.AreEqual (4, array.Dimensions [0].UpperBound); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void EnumFieldsConstant (ModuleDefinition module) |
||||
{ |
||||
var pim = module.GetType ("Pim"); |
||||
Assert.IsNotNull (pim); |
||||
|
||||
var field = pim.GetField ("Pam"); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.AreEqual (1, (int) field.Constant); |
||||
|
||||
field = pim.GetField ("Poum"); |
||||
Assert.AreEqual (2, (int) field.Constant); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void StringAndClassConstant (ModuleDefinition module) |
||||
{ |
||||
var panpan = module.GetType ("PanPan"); |
||||
Assert.IsNotNull (panpan); |
||||
|
||||
var field = panpan.GetField ("Peter"); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsNull (field.Constant); |
||||
|
||||
field = panpan.GetField ("QQ"); |
||||
Assert.AreEqual ("qq", (string) field.Constant); |
||||
|
||||
field = panpan.GetField ("nil"); |
||||
Assert.AreEqual (null, (string) field.Constant); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void ObjectConstant (ModuleDefinition module) |
||||
{ |
||||
var panpan = module.GetType ("PanPan"); |
||||
Assert.IsNotNull (panpan); |
||||
|
||||
var field = panpan.GetField ("obj"); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsNull (field.Constant); |
||||
} |
||||
|
||||
[TestIL ("types.il")] |
||||
public void NullPrimitiveConstant (ModuleDefinition module) |
||||
{ |
||||
var fields = module.GetType ("Fields"); |
||||
|
||||
var field = fields.GetField ("int32_nullref"); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.AreEqual (null, field.Constant); |
||||
} |
||||
|
||||
[TestCSharp ("Fields.cs")] |
||||
public void ArrayConstant (ModuleDefinition module) |
||||
{ |
||||
var panpan = module.GetType ("PanPan"); |
||||
Assert.IsNotNull (panpan); |
||||
|
||||
var field = panpan.GetField ("ints"); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsNull (field.Constant); |
||||
} |
||||
|
||||
[TestIL ("types.il")] |
||||
public void ConstantCoalescing (ModuleDefinition module) |
||||
{ |
||||
var fields = module.GetType ("Fields"); |
||||
|
||||
var field = fields.GetField ("int32_int16"); |
||||
Assert.AreEqual ("System.Int32", field.FieldType.FullName); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsInstanceOfType (typeof (short), field.Constant); |
||||
Assert.AreEqual ((short) 1, field.Constant); |
||||
|
||||
field = fields.GetField ("int16_int32"); |
||||
Assert.AreEqual ("System.Int16", field.FieldType.FullName); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsInstanceOfType (typeof (int), field.Constant); |
||||
Assert.AreEqual (1, field.Constant); |
||||
|
||||
field = fields.GetField ("char_int16"); |
||||
Assert.AreEqual ("System.Char", field.FieldType.FullName); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsInstanceOfType (typeof (short), field.Constant); |
||||
Assert.AreEqual ((short) 1, field.Constant); |
||||
|
||||
field = fields.GetField ("int16_char"); |
||||
Assert.AreEqual ("System.Int16", field.FieldType.FullName); |
||||
Assert.IsTrue (field.HasConstant); |
||||
Assert.IsInstanceOfType (typeof (char), field.Constant); |
||||
Assert.AreEqual ('s', field.Constant); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void NestedEnumOfGenericTypeDefinition (ModuleDefinition module) |
||||
{ |
||||
var dang = module.GetType ("Bongo`1/Dang"); |
||||
Assert.IsNotNull (dang); |
||||
|
||||
var field = dang.GetField ("Ding"); |
||||
Assert.IsNotNull (field); |
||||
Assert.AreEqual (2, field.Constant); |
||||
|
||||
field = dang.GetField ("Dong"); |
||||
Assert.IsNotNull (field); |
||||
Assert.AreEqual (12, field.Constant); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void MarshalAsFixedStr (ModuleDefinition module) |
||||
{ |
||||
var boc = module.GetType ("Boc"); |
||||
var field = boc.GetField ("a"); |
||||
|
||||
Assert.IsNotNull (field); |
||||
|
||||
Assert.IsTrue (field.HasMarshalInfo); |
||||
|
||||
var info = (FixedSysStringMarshalInfo) field.MarshalInfo; |
||||
|
||||
Assert.AreEqual (42, info.Size); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void MarshalAsFixedArray (ModuleDefinition module) |
||||
{ |
||||
var boc = module.GetType ("Boc"); |
||||
var field = boc.GetField ("b"); |
||||
|
||||
Assert.IsNotNull (field); |
||||
|
||||
Assert.IsTrue (field.HasMarshalInfo); |
||||
|
||||
var info = (FixedArrayMarshalInfo) field.MarshalInfo; |
||||
|
||||
Assert.AreEqual (12, info.Size); |
||||
Assert.AreEqual (NativeType.Boolean, info.ElementType); |
||||
} |
||||
|
||||
static TypeDefinition GetPrivateImplementationType (ModuleDefinition module) |
||||
{ |
||||
foreach (var type in module.Types) |
||||
if (type.FullName.Contains ("<PrivateImplementationDetails>")) |
||||
return type; |
||||
|
||||
return null; |
||||
} |
||||
|
||||
static void AssertField (TypeDefinition type, string name, Type expected) |
||||
{ |
||||
var field = type.GetField (name); |
||||
Assert.IsNotNull (field, name); |
||||
|
||||
Assert.AreEqual (expected.FullName, field.FieldType.FullName); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
using System; |
||||
using System.IO; |
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
public static class Formatter { |
||||
|
||||
public static string FormatInstruction (Instruction instruction) |
||||
{ |
||||
var writer = new StringWriter (); |
||||
WriteInstruction (writer, instruction); |
||||
return writer.ToString (); |
||||
} |
||||
|
||||
public static string FormatMethodBody (MethodDefinition method) |
||||
{ |
||||
var writer = new StringWriter (); |
||||
WriteMethodBody (writer, method); |
||||
return writer.ToString (); |
||||
} |
||||
|
||||
public static void WriteMethodBody (TextWriter writer, MethodDefinition method) |
||||
{ |
||||
var body = method.Body; |
||||
|
||||
WriteVariables (writer, body); |
||||
|
||||
foreach (Instruction instruction in body.Instructions) { |
||||
var sequence_point = instruction.SequencePoint; |
||||
if (sequence_point != null) { |
||||
writer.Write ('\t'); |
||||
WriteSequencePoint (writer, sequence_point); |
||||
writer.WriteLine (); |
||||
} |
||||
|
||||
writer.Write ('\t'); |
||||
WriteInstruction (writer, instruction); |
||||
writer.WriteLine (); |
||||
} |
||||
|
||||
WriteExceptionHandlers (writer, body); |
||||
} |
||||
|
||||
static void WriteVariables (TextWriter writer, MethodBody body) |
||||
{ |
||||
var variables = body.Variables; |
||||
|
||||
writer.Write ('\t'); |
||||
writer.Write (".locals {0}(", body.InitLocals ? "init " : string.Empty); |
||||
|
||||
for (int i = 0; i < variables.Count; i++) { |
||||
if (i > 0) |
||||
writer.Write (", "); |
||||
|
||||
var variable = variables [i]; |
||||
|
||||
writer.Write ("{0} {1}", variable.VariableType, variable); |
||||
} |
||||
writer.WriteLine (")"); |
||||
} |
||||
|
||||
static void WriteInstruction (TextWriter writer, Instruction instruction) |
||||
{ |
||||
writer.Write (FormatLabel (instruction.Offset)); |
||||
writer.Write (": "); |
||||
writer.Write (instruction.OpCode.Name); |
||||
if (null != instruction.Operand) { |
||||
writer.Write (' '); |
||||
WriteOperand (writer, instruction.Operand); |
||||
} |
||||
} |
||||
|
||||
static void WriteSequencePoint (TextWriter writer, SequencePoint sequence_point) |
||||
{ |
||||
writer.Write (".line {0},{1}:{2},{3} '{4}'", |
||||
sequence_point.StartLine, |
||||
sequence_point.EndLine, |
||||
sequence_point.StartColumn, |
||||
sequence_point.EndColumn, |
||||
sequence_point.Document.Url); |
||||
} |
||||
|
||||
static string FormatLabel (int offset) |
||||
{ |
||||
string label = "000" + offset.ToString ("x"); |
||||
return "IL_" + label.Substring (label.Length - 4); |
||||
} |
||||
|
||||
static string FormatLabel (Instruction instruction) |
||||
{ |
||||
return FormatLabel (instruction.Offset); |
||||
} |
||||
|
||||
static void WriteOperand (TextWriter writer, object operand) |
||||
{ |
||||
if (null == operand) throw new ArgumentNullException ("operand"); |
||||
|
||||
var target = operand as Instruction; |
||||
if (null != target) { |
||||
writer.Write (FormatLabel (target.Offset)); |
||||
return; |
||||
} |
||||
|
||||
var targets = operand as Instruction []; |
||||
if (null != targets) { |
||||
WriteLabelList (writer, targets); |
||||
return; |
||||
} |
||||
|
||||
string s = operand as string; |
||||
if (null != s) { |
||||
writer.Write ("\"" + s + "\""); |
||||
return; |
||||
} |
||||
|
||||
s = ToInvariantCultureString (operand); |
||||
writer.Write (s); |
||||
} |
||||
|
||||
static void WriteLabelList (TextWriter writer, Instruction [] instructions) |
||||
{ |
||||
writer.Write ("("); |
||||
|
||||
for (int i = 0; i < instructions.Length; i++) { |
||||
if (i != 0) writer.Write (", "); |
||||
writer.Write (FormatLabel (instructions [i].Offset)); |
||||
} |
||||
|
||||
writer.Write (")"); |
||||
} |
||||
|
||||
static void WriteExceptionHandlers (TextWriter writer, MethodBody body) |
||||
{ |
||||
if (!body.HasExceptionHandlers) |
||||
return; |
||||
|
||||
foreach (var handler in body.ExceptionHandlers) { |
||||
writer.Write ("\t"); |
||||
writer.WriteLine (".try {0} to {1} {2} handler {3} to {4}", |
||||
FormatLabel (handler.TryStart), |
||||
FormatLabel (handler.TryEnd), |
||||
FormatHandlerType (handler), |
||||
FormatLabel (handler.HandlerStart), |
||||
FormatLabel (handler.HandlerEnd)); |
||||
} |
||||
} |
||||
|
||||
static string FormatHandlerType (ExceptionHandler handler) |
||||
{ |
||||
var handler_type = handler.HandlerType; |
||||
var type = handler_type.ToString ().ToLowerInvariant (); |
||||
|
||||
switch (handler_type) { |
||||
case ExceptionHandlerType.Catch: |
||||
return string.Format ("{0} {1}", type, handler.CatchType.FullName); |
||||
case ExceptionHandlerType.Filter: |
||||
throw new NotImplementedException (); |
||||
default: |
||||
return type; |
||||
} |
||||
} |
||||
|
||||
public static string ToInvariantCultureString (object value) |
||||
{ |
||||
var convertible = value as IConvertible; |
||||
return (null != convertible) |
||||
? convertible.ToString (System.Globalization.CultureInfo.InvariantCulture) |
||||
: value.ToString (); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ILProcessorTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void Append () |
||||
{ |
||||
var method = CreateTestMethod (); |
||||
var il = method.GetILProcessor (); |
||||
|
||||
var ret = il.Create (OpCodes.Ret); |
||||
il.Append (ret); |
||||
|
||||
AssertOpCodeSequence (new [] { OpCodes.Ret }, method); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertBefore () |
||||
{ |
||||
var method = CreateTestMethod (OpCodes.Ldloc_0, OpCodes.Ldloc_2, OpCodes.Ldloc_3); |
||||
var il = method.GetILProcessor (); |
||||
|
||||
var ldloc_2 = method.Instructions.Where (i => i.OpCode == OpCodes.Ldloc_2).First (); |
||||
|
||||
il.InsertBefore ( |
||||
ldloc_2, |
||||
il.Create (OpCodes.Ldloc_1)); |
||||
|
||||
AssertOpCodeSequence (new [] { OpCodes.Ldloc_0, OpCodes.Ldloc_1, OpCodes.Ldloc_2, OpCodes.Ldloc_3 }, method); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertAfter () |
||||
{ |
||||
var method = CreateTestMethod (OpCodes.Ldloc_0, OpCodes.Ldloc_2, OpCodes.Ldloc_3); |
||||
var il = method.GetILProcessor (); |
||||
|
||||
var ldloc_0 = method.Instructions.First (); |
||||
|
||||
il.InsertAfter ( |
||||
ldloc_0, |
||||
il.Create (OpCodes.Ldloc_1)); |
||||
|
||||
AssertOpCodeSequence (new [] { OpCodes.Ldloc_0, OpCodes.Ldloc_1, OpCodes.Ldloc_2, OpCodes.Ldloc_3 }, method); |
||||
} |
||||
|
||||
static void AssertOpCodeSequence (OpCode [] expected, MethodBody body) |
||||
{ |
||||
var opcodes = body.Instructions.Select (i => i.OpCode).ToArray (); |
||||
Assert.AreEqual (expected.Length, opcodes.Length); |
||||
|
||||
for (int i = 0; i < opcodes.Length; i++) |
||||
Assert.AreEqual (expected [i], opcodes [i]); |
||||
} |
||||
|
||||
static MethodBody CreateTestMethod (params OpCode [] opcodes) |
||||
{ |
||||
var method = new MethodDefinition { |
||||
Name = "function", |
||||
}; |
||||
|
||||
var il = method.Body.GetILProcessor (); |
||||
|
||||
foreach (var opcode in opcodes) |
||||
il.Emit (opcode); |
||||
|
||||
return method.Body; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,127 @@
@@ -0,0 +1,127 @@
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.PE; |
||||
using Mono.Cecil.Metadata; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ImageReadTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void ImageSections () |
||||
{ |
||||
var image = GetResourceImage ("hello.exe"); |
||||
|
||||
Assert.AreEqual (3, image.Sections.Length); |
||||
Assert.AreEqual (".text", image.Sections [0].Name); |
||||
Assert.AreEqual (".rsrc", image.Sections [1].Name); |
||||
Assert.AreEqual (".reloc", image.Sections [2].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImageMetadataVersion () |
||||
{ |
||||
var image = GetResourceImage ("hello.exe"); |
||||
Assert.AreEqual (TargetRuntime.Net_2_0, image.Runtime); |
||||
|
||||
image = GetResourceImage ("hello1.exe"); |
||||
Assert.AreEqual (TargetRuntime.Net_1_1, image.Runtime); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImageModuleKind () |
||||
{ |
||||
var image = GetResourceImage ("hello.exe"); |
||||
Assert.AreEqual (ModuleKind.Console, image.Kind); |
||||
|
||||
image = GetResourceImage ("libhello.dll"); |
||||
Assert.AreEqual (ModuleKind.Dll, image.Kind); |
||||
|
||||
image = GetResourceImage ("hellow.exe"); |
||||
Assert.AreEqual (ModuleKind.Windows, image.Kind); |
||||
} |
||||
|
||||
[Test] |
||||
public void MetadataHeaps () |
||||
{ |
||||
var image = GetResourceImage ("hello.exe"); |
||||
|
||||
Assert.IsNotNull (image.TableHeap); |
||||
|
||||
Assert.IsNotNull (image.StringHeap); |
||||
Assert.AreEqual (string.Empty, image.StringHeap.Read (0)); |
||||
Assert.AreEqual ("<Module>", image.StringHeap.Read (1)); |
||||
|
||||
Assert.IsNotNull (image.UserStringHeap); |
||||
Assert.AreEqual (string.Empty, image.UserStringHeap.Read (0)); |
||||
Assert.AreEqual ("Hello Cecil World !", image.UserStringHeap.Read (1)); |
||||
|
||||
Assert.IsNotNull (image.GuidHeap); |
||||
Assert.AreEqual (new Guid (), image.GuidHeap.Read (0)); |
||||
Assert.AreEqual (new Guid ("C3BC2BD3-2576-4D00-A80E-465B5632415F"), image.GuidHeap.Read (1)); |
||||
|
||||
Assert.IsNotNull (image.BlobHeap); |
||||
Assert.AreEqual (new byte [0], image.BlobHeap.Read (0)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TablesHeap () |
||||
{ |
||||
var image = GetResourceImage ("hello.exe"); |
||||
var heap = image.TableHeap; |
||||
|
||||
Assert.IsNotNull (heap); |
||||
|
||||
Assert.AreEqual (1, heap [Table.Module].Length); |
||||
Assert.AreEqual (4, heap [Table.TypeRef].Length); |
||||
Assert.AreEqual (2, heap [Table.TypeDef].Length); |
||||
Assert.AreEqual (0, heap [Table.Field].Length); |
||||
Assert.AreEqual (2, heap [Table.Method].Length); |
||||
Assert.AreEqual (4, heap [Table.MemberRef].Length); |
||||
Assert.AreEqual (2, heap [Table.CustomAttribute].Length); |
||||
Assert.AreEqual (1, heap [Table.Assembly].Length); |
||||
Assert.AreEqual (1, heap [Table.AssemblyRef].Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadX64Image () |
||||
{ |
||||
var image = GetResourceImage ("hello.x64.exe"); |
||||
|
||||
Assert.AreEqual (TargetArchitecture.AMD64, image.Architecture); |
||||
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadIA64Image () |
||||
{ |
||||
var image = GetResourceImage ("hello.ia64.exe"); |
||||
|
||||
Assert.AreEqual (TargetArchitecture.IA64, image.Architecture); |
||||
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadX86Image () |
||||
{ |
||||
var image = GetResourceImage ("hello.x86.exe"); |
||||
|
||||
Assert.AreEqual (TargetArchitecture.I386, image.Architecture); |
||||
Assert.AreEqual (ModuleAttributes.ILOnly | ModuleAttributes.Required32Bit, image.Attributes); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadAnyCpuImage () |
||||
{ |
||||
var image = GetResourceImage ("hello.anycpu.exe"); |
||||
|
||||
Assert.AreEqual (TargetArchitecture.I386, image.Architecture); |
||||
Assert.AreEqual (ModuleAttributes.ILOnly, image.Attributes); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,310 @@
@@ -0,0 +1,310 @@
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using SR = System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ImportCecilTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void ImportStringByRef () |
||||
{ |
||||
var get_string = Compile<Func<string, string>> ((module, body) => { |
||||
var type = module.Types [1]; |
||||
|
||||
var method_by_ref = new MethodDefinition { |
||||
Name = "ModifyString", |
||||
IsPrivate = true, |
||||
IsStatic = true, |
||||
}; |
||||
|
||||
type.Methods.Add (method_by_ref); |
||||
|
||||
method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void).ToDefinition ()); |
||||
|
||||
method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).ToDefinition ()))); |
||||
method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (new ByReferenceType (typeof (string).ToDefinition ())))); |
||||
|
||||
var m_il = method_by_ref.Body.GetILProcessor (); |
||||
m_il.Emit (OpCodes.Ldarg_1); |
||||
m_il.Emit (OpCodes.Ldarg_0); |
||||
m_il.Emit (OpCodes.Stind_Ref); |
||||
m_il.Emit (OpCodes.Ret); |
||||
|
||||
var v_0 = new VariableDefinition (module.Import (typeof (string).ToDefinition ())); |
||||
body.Variables.Add (v_0); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Stloc, v_0); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldloca, v_0); |
||||
il.Emit (OpCodes.Call, method_by_ref); |
||||
il.Emit (OpCodes.Ldloc_0); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("foo", get_string ("foo")); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportStringArray () |
||||
{ |
||||
var identity = Compile<Func<string [,], string [,]>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
var array = new string [2, 2]; |
||||
|
||||
Assert.AreEqual (array, identity (array)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportFieldStringEmpty () |
||||
{ |
||||
var get_empty = Compile<Func<string>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty").ToDefinition ())); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("", get_empty ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportStringConcat () |
||||
{ |
||||
var concat = Compile<Func<string, string, string>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }).ToDefinition ())); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("FooBar", concat ("Foo", "Bar")); |
||||
} |
||||
|
||||
public class Generic<T> { |
||||
public T Field; |
||||
|
||||
public T Method (T t) |
||||
{ |
||||
return t; |
||||
} |
||||
|
||||
public TS GenericMethod<TS> (T t, TS s) |
||||
{ |
||||
return s; |
||||
} |
||||
|
||||
public Generic<TS> ComplexGenericMethod<TS> (T t, TS s) |
||||
{ |
||||
return new Generic<TS> { Field = s }; |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericField () |
||||
{ |
||||
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => { |
||||
var generic_def = module.Import (typeof (Generic<>)).Resolve (); |
||||
var field_def = generic_def.Fields.Where (f => f.Name == "Field").First (); |
||||
|
||||
var field_string = field_def.MakeGeneric (module.Import (typeof (string))); |
||||
|
||||
var field_ref = module.Import (field_string); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldfld, field_ref); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
var generic = new Generic<string> { |
||||
Field = "foo", |
||||
}; |
||||
|
||||
Assert.AreEqual ("foo", get_field (generic)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethod () |
||||
{ |
||||
var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => { |
||||
var generic_def = module.Import (typeof (Generic<>)).Resolve (); |
||||
var method_def = generic_def.Methods.Where (m => m.Name == "Method").First (); |
||||
|
||||
var method_int = method_def.MakeGeneric (module.Import (typeof (int))); |
||||
var method_ref = module.Import (method_int); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, method_ref); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, generic_identity (new Generic<int> (), 42)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethodSpec () |
||||
{ |
||||
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { |
||||
var generic_def = module.Import (typeof (Generic<>)).Resolve (); |
||||
var method_def = generic_def.Methods.Where (m => m.Name == "GenericMethod").First (); |
||||
|
||||
var method_string = method_def.MakeGeneric (module.Import (typeof (string))); |
||||
|
||||
var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int))); |
||||
|
||||
var method_ref = module.Import (method_instance); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, method_ref); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, gen_spec_id (new Generic<string> (), 42)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportComplexGenericMethodSpec () |
||||
{ |
||||
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { |
||||
var generic_def = module.Import (typeof (Generic<>)).Resolve (); |
||||
var method_def = generic_def.Methods.Where (m => m.Name == "ComplexGenericMethod").First (); |
||||
|
||||
var method_string = method_def.MakeGeneric (module.Import (typeof (string))); |
||||
var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int))); |
||||
var method_ref = module.Import (method_instance); |
||||
|
||||
var field_def = generic_def.Fields.Where (f => f.Name == "Field").First (); |
||||
var field_int = field_def.MakeGeneric (module.Import (typeof (int))); |
||||
var field_ref = module.Import (field_int); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, method_ref); |
||||
il.Emit (OpCodes.Ldfld, field_ref); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, gen_spec_id (new Generic<string> (), 42)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportMethodOnOpenGeneric () |
||||
{ |
||||
var generic = typeof (Generic<>).ToDefinition (); |
||||
var module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll); |
||||
|
||||
var method = module.Import (generic.GetMethod ("Method")); |
||||
|
||||
Assert.AreEqual ("T Mono.Cecil.Tests.ImportCecilTests/Generic`1::Method(T)", method.FullName); |
||||
} |
||||
|
||||
delegate void Emitter (ModuleDefinition module, MethodBody body); |
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)] |
||||
static TDelegate Compile<TDelegate> (Emitter emitter) |
||||
where TDelegate : class |
||||
{ |
||||
var name = GetTestCaseName (); |
||||
|
||||
var module = CreateTestModule<TDelegate> (name, emitter); |
||||
var assembly = LoadTestModule (module); |
||||
|
||||
return CreateRunDelegate<TDelegate> (GetTestCase (name, assembly)); |
||||
} |
||||
|
||||
static TDelegate CreateRunDelegate<TDelegate> (Type type) |
||||
where TDelegate : class |
||||
{ |
||||
return (TDelegate) (object) Delegate.CreateDelegate (typeof (TDelegate), type.GetMethod ("Run")); |
||||
} |
||||
|
||||
static Type GetTestCase (string name, SR.Assembly assembly) |
||||
{ |
||||
return assembly.GetType (name); |
||||
} |
||||
|
||||
static SR.Assembly LoadTestModule (ModuleDefinition module) |
||||
{ |
||||
using (var stream = new MemoryStream ()) { |
||||
module.Write (stream); |
||||
File.WriteAllBytes (Path.Combine (Path.Combine (Path.GetTempPath (), "cecil"), module.Name + ".dll"), stream.ToArray ()); |
||||
return SR.Assembly.Load (stream.ToArray ()); |
||||
} |
||||
} |
||||
|
||||
static ModuleDefinition CreateTestModule<TDelegate> (string name, Emitter emitter) |
||||
{ |
||||
var module = CreateModule (name); |
||||
|
||||
var type = new TypeDefinition ( |
||||
"", |
||||
name, |
||||
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, |
||||
module.Import (typeof (object))); |
||||
|
||||
module.Types.Add (type); |
||||
|
||||
var method = CreateMethod (type, typeof (TDelegate).GetMethod ("Invoke")); |
||||
|
||||
emitter (module, method.Body); |
||||
|
||||
return module; |
||||
} |
||||
|
||||
static MethodDefinition CreateMethod (TypeDefinition type, SR.MethodInfo pattern) |
||||
{ |
||||
var module = type.Module; |
||||
|
||||
var method = new MethodDefinition { |
||||
Name = "Run", |
||||
IsPublic = true, |
||||
IsStatic = true, |
||||
}; |
||||
|
||||
type.Methods.Add (method); |
||||
|
||||
method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType); |
||||
|
||||
foreach (var parameter_pattern in pattern.GetParameters ()) |
||||
method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType))); |
||||
|
||||
return method; |
||||
} |
||||
|
||||
static ModuleDefinition CreateModule (string name) |
||||
{ |
||||
return ModuleDefinition.CreateModule (name, ModuleKind.Dll); |
||||
} |
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)] |
||||
static string GetTestCaseName () |
||||
{ |
||||
var stack_trace = new StackTrace (); |
||||
var stack_frame = stack_trace.GetFrame (2); |
||||
|
||||
return "ImportCecil_" + stack_frame.GetMethod ().Name; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,409 @@
@@ -0,0 +1,409 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using SR = System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ImportReflectionTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void ImportString () |
||||
{ |
||||
var get_string = Compile<Func<string>> ((_, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldstr, "yo dawg!"); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("yo dawg!", get_string ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportInt () |
||||
{ |
||||
var add = Compile<Func<int, int, int>> ((_, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Add); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, add (40, 2)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportStringByRef () |
||||
{ |
||||
var get_string = Compile<Func<string, string>> ((module, body) => { |
||||
var type = module.Types [1]; |
||||
|
||||
var method_by_ref = new MethodDefinition { |
||||
Name = "ModifyString", |
||||
IsPrivate = true, |
||||
IsStatic = true, |
||||
}; |
||||
|
||||
type.Methods.Add (method_by_ref); |
||||
|
||||
method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void)); |
||||
|
||||
method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string)))); |
||||
method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).MakeByRefType ()))); |
||||
|
||||
var m_il = method_by_ref.Body.GetILProcessor (); |
||||
m_il.Emit (OpCodes.Ldarg_1); |
||||
m_il.Emit (OpCodes.Ldarg_0); |
||||
m_il.Emit (OpCodes.Stind_Ref); |
||||
m_il.Emit (OpCodes.Ret); |
||||
|
||||
var v_0 = new VariableDefinition (module.Import (typeof (string))); |
||||
body.Variables.Add (v_0); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Stloc, v_0); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldloca, v_0); |
||||
il.Emit (OpCodes.Call, method_by_ref); |
||||
il.Emit (OpCodes.Ldloc_0); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("foo", get_string ("foo")); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportStringArray () |
||||
{ |
||||
var identity = Compile<Func<string [,], string [,]>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
var array = new string [2, 2]; |
||||
|
||||
Assert.AreEqual (array, identity (array)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportFieldStringEmpty () |
||||
{ |
||||
var get_empty = Compile<Func<string>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty"))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("", get_empty ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportStringConcat () |
||||
{ |
||||
var concat = Compile<Func<string, string, string>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual ("FooBar", concat ("Foo", "Bar")); |
||||
} |
||||
|
||||
public class Generic<T> { |
||||
public T Field; |
||||
|
||||
public T Method (T t) |
||||
{ |
||||
return t; |
||||
} |
||||
|
||||
public TS GenericMethod<TS> (T t, TS s) |
||||
{ |
||||
return s; |
||||
} |
||||
|
||||
public Generic<TS> ComplexGenericMethod<TS> (T t, TS s) |
||||
{ |
||||
return new Generic<TS> { Field = s }; |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericField () |
||||
{ |
||||
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field"))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
var generic = new Generic<string> { |
||||
Field = "foo", |
||||
}; |
||||
|
||||
Assert.AreEqual ("foo", get_field (generic)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethod () |
||||
{ |
||||
var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<int>).GetMethod ("Method"))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, generic_identity (new Generic<int> (), 42)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethodSpec () |
||||
{ |
||||
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, gen_spec_id (new Generic<string> (), 42)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportComplexGenericMethodSpec () |
||||
{ |
||||
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => { |
||||
var il = body.GetILProcessor (); |
||||
il.Emit (OpCodes.Ldarg_0); |
||||
il.Emit (OpCodes.Ldnull); |
||||
il.Emit (OpCodes.Ldarg_1); |
||||
il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("ComplexGenericMethod").MakeGenericMethod (typeof (int)))); |
||||
il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field"))); |
||||
il.Emit (OpCodes.Ret); |
||||
}); |
||||
|
||||
Assert.AreEqual (42, gen_spec_id (new Generic<string> (), 42)); |
||||
} |
||||
|
||||
public class Foo<TFoo> { |
||||
public List<TFoo> list; |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericTypeDefOrOpen () |
||||
{ |
||||
var module = typeof (Foo<>).ToDefinition ().Module; |
||||
|
||||
var foo_def = module.Import (typeof (Foo<>)); |
||||
var foo_open = module.Import (typeof (Foo<>), foo_def); |
||||
|
||||
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1", foo_def.FullName); |
||||
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>", foo_open.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericTypeFromContext () |
||||
{ |
||||
var list_foo = typeof (Foo<>).GetField ("list").FieldType; |
||||
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo); |
||||
|
||||
var foo_def = typeof (Foo<>).ToDefinition (); |
||||
var module = foo_def.Module; |
||||
|
||||
var generic_foo = module.Import (generic_list_foo_open, foo_def); |
||||
|
||||
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>", |
||||
generic_foo.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericTypeDefFromContext () |
||||
{ |
||||
var foo_open = typeof (Foo<>).MakeGenericType (typeof (Foo<>).GetGenericArguments () [0]); |
||||
var generic_foo_open = typeof (Generic<>).MakeGenericType (foo_open); |
||||
|
||||
var foo_def = typeof (Foo<>).ToDefinition (); |
||||
var module = foo_def.Module; |
||||
|
||||
var generic_foo = module.Import (generic_foo_open, foo_def); |
||||
|
||||
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>>", |
||||
generic_foo.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportArrayTypeDefFromContext () |
||||
{ |
||||
var foo_open = typeof (Foo<>).MakeGenericType (typeof (Foo<>).GetGenericArguments () [0]); |
||||
var foo_open_array = foo_open.MakeArrayType (); |
||||
|
||||
var foo_def = typeof (Foo<>).ToDefinition (); |
||||
var module = foo_def.Module; |
||||
|
||||
var array_foo = module.Import (foo_open_array, foo_def); |
||||
|
||||
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>[]", |
||||
array_foo.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericFieldFromContext () |
||||
{ |
||||
var list_foo = typeof (Foo<>).GetField ("list").FieldType; |
||||
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo); |
||||
var generic_list_foo_open_field = generic_list_foo_open.GetField ("Field"); |
||||
|
||||
var foo_def = typeof (Foo<>).ToDefinition (); |
||||
var module = foo_def.Module; |
||||
|
||||
var generic_field = module.Import (generic_list_foo_open_field, foo_def); |
||||
|
||||
Assert.AreEqual ("TFoo Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Field", |
||||
generic_field.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethodFromContext () |
||||
{ |
||||
var list_foo = typeof (Foo<>).GetField ("list").FieldType; |
||||
var generic_list_foo_open = typeof (Generic<>).MakeGenericType (list_foo); |
||||
var generic_list_foo_open_method = generic_list_foo_open.GetMethod ("Method"); |
||||
|
||||
var foo_def = typeof (Foo<>).ToDefinition (); |
||||
var module = foo_def.Module; |
||||
|
||||
var generic_method = module.Import (generic_list_foo_open_method, foo_def); |
||||
|
||||
Assert.AreEqual ("TFoo Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Method(TFoo)", |
||||
generic_method.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportMethodOnOpenGenericType () |
||||
{ |
||||
var module = typeof (Generic<>).ToDefinition ().Module; |
||||
|
||||
var method = module.Import (typeof (Generic<>).GetMethod ("Method")); |
||||
|
||||
Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::Method(T)", method.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void ImportGenericMethodOnOpenGenericType () |
||||
{ |
||||
var module = typeof (Generic<>).ToDefinition ().Module; |
||||
|
||||
var generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod")); |
||||
|
||||
Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod(T,TS)", generic_method.FullName); |
||||
|
||||
generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod"), generic_method); |
||||
|
||||
Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod<TS>(T,TS)", generic_method.FullName); |
||||
} |
||||
|
||||
delegate void Emitter (ModuleDefinition module, MethodBody body); |
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)] |
||||
static TDelegate Compile<TDelegate> (Emitter emitter) |
||||
where TDelegate : class |
||||
{ |
||||
var name = GetTestCaseName (); |
||||
|
||||
var module = CreateTestModule<TDelegate> (name, emitter); |
||||
var assembly = LoadTestModule (module); |
||||
|
||||
return CreateRunDelegate<TDelegate> (GetTestCase (name, assembly)); |
||||
} |
||||
|
||||
static TDelegate CreateRunDelegate<TDelegate> (Type type) |
||||
where TDelegate : class |
||||
{ |
||||
return (TDelegate) (object) Delegate.CreateDelegate (typeof (TDelegate), type.GetMethod ("Run")); |
||||
} |
||||
|
||||
static Type GetTestCase (string name, SR.Assembly assembly) |
||||
{ |
||||
return assembly.GetType (name); |
||||
} |
||||
|
||||
static SR.Assembly LoadTestModule (ModuleDefinition module) |
||||
{ |
||||
using (var stream = new MemoryStream ()) { |
||||
module.Write (stream); |
||||
File.WriteAllBytes (Path.Combine (Path.Combine (Path.GetTempPath (), "cecil"), module.Name + ".dll"), stream.ToArray ()); |
||||
return SR.Assembly.Load (stream.ToArray ()); |
||||
} |
||||
} |
||||
|
||||
static ModuleDefinition CreateTestModule<TDelegate> (string name, Emitter emitter) |
||||
{ |
||||
var module = CreateModule (name); |
||||
|
||||
var type = new TypeDefinition ( |
||||
"", |
||||
name, |
||||
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, |
||||
module.Import (typeof (object))); |
||||
|
||||
module.Types.Add (type); |
||||
|
||||
var method = CreateMethod (type, typeof (TDelegate).GetMethod ("Invoke")); |
||||
|
||||
emitter (module, method.Body); |
||||
|
||||
return module; |
||||
} |
||||
|
||||
static MethodDefinition CreateMethod (TypeDefinition type, SR.MethodInfo pattern) |
||||
{ |
||||
var module = type.Module; |
||||
|
||||
var method = new MethodDefinition { |
||||
Name = "Run", |
||||
IsPublic = true, |
||||
IsStatic = true, |
||||
}; |
||||
|
||||
type.Methods.Add (method); |
||||
|
||||
method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType); |
||||
|
||||
foreach (var parameter_pattern in pattern.GetParameters ()) |
||||
method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType))); |
||||
|
||||
return method; |
||||
} |
||||
|
||||
static ModuleDefinition CreateModule (string name) |
||||
{ |
||||
return ModuleDefinition.CreateModule (name, ModuleKind.Dll); |
||||
} |
||||
|
||||
[MethodImpl (MethodImplOptions.NoInlining)] |
||||
static string GetTestCaseName () |
||||
{ |
||||
var stack_trace = new StackTrace (); |
||||
var stack_frame = stack_trace.GetFrame (2); |
||||
|
||||
return "ImportReflection_" + stack_frame.GetMethod ().Name; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
using Mono; |
||||
|
||||
#if !NET_3_5 && !NET_4_0
|
||||
|
||||
namespace System.Linq { |
||||
|
||||
static class Enumerable { |
||||
|
||||
public static IEnumerable<TRet> Select<TItem, TRet> (this IEnumerable<TItem> self, Func<TItem, TRet> selector) |
||||
{ |
||||
foreach (var item in self) |
||||
yield return selector (item); |
||||
} |
||||
|
||||
public static IEnumerable<T> Where<T> (this IEnumerable<T> self, Func<T, bool> predicate) |
||||
{ |
||||
foreach (var item in self) |
||||
if (predicate (item)) |
||||
yield return item; |
||||
} |
||||
|
||||
public static List<T> ToList<T> (this IEnumerable<T> self) |
||||
{ |
||||
return new List<T> (self); |
||||
} |
||||
|
||||
public static T [] ToArray<T> (this IEnumerable<T> self) |
||||
{ |
||||
return self.ToList ().ToArray (); |
||||
} |
||||
|
||||
public static T First<T> (this IEnumerable<T> self) |
||||
{ |
||||
using (var enumerator = self.GetEnumerator ()) { |
||||
if (!enumerator.MoveNext ()) |
||||
throw new InvalidOperationException (); |
||||
|
||||
return enumerator.Current; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endif
|
||||
@ -0,0 +1,363 @@
@@ -0,0 +1,363 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class MethodBodyTests : BaseTestFixture { |
||||
|
||||
[TestIL ("hello.il")] |
||||
public void MultiplyMethod (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
Assert.IsNotNull (foo); |
||||
|
||||
var bar = foo.GetMethod ("Bar"); |
||||
Assert.IsNotNull (bar); |
||||
Assert.IsTrue (bar.IsIL); |
||||
|
||||
AssertCode (@"
|
||||
.locals init (System.Int32 V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldarg.1 |
||||
IL_0002: mul |
||||
IL_0003: stloc.0 |
||||
IL_0004: ldloc.0 |
||||
IL_0005: call System.Void Foo::Baz(System.Int32) |
||||
IL_000a: ret |
||||
", bar);
|
||||
} |
||||
|
||||
[TestIL ("hello.il")] |
||||
public void PrintStringEmpty (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
Assert.IsNotNull (foo); |
||||
|
||||
var print_empty = foo.GetMethod ("PrintEmpty"); |
||||
Assert.IsNotNull (print_empty); |
||||
|
||||
AssertCode (@"
|
||||
.locals () |
||||
IL_0000: ldsfld System.String System.String::Empty |
||||
IL_0005: call System.Void System.Console::WriteLine(System.String) |
||||
IL_000a: ret |
||||
", print_empty);
|
||||
} |
||||
|
||||
[TestModule ("libhello.dll")] |
||||
public void Branch (ModuleDefinition module) |
||||
{ |
||||
var lib = module.GetType ("Library"); |
||||
Assert.IsNotNull (lib); |
||||
|
||||
var method = lib.GetMethod ("GetHelloString"); |
||||
Assert.IsNotNull (method); |
||||
|
||||
AssertCode (@"
|
||||
.locals init (System.String V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldstr ""hello world of tomorrow"" |
||||
IL_0006: stloc.0 |
||||
IL_0007: br.s IL_0009 |
||||
IL_0009: ldloc.0 |
||||
IL_000a: ret |
||||
", method);
|
||||
} |
||||
|
||||
[TestModule ("switch.exe")] |
||||
public void Switch (ModuleDefinition module) |
||||
{ |
||||
var program = module.GetType ("Program"); |
||||
Assert.IsNotNull (program); |
||||
|
||||
var method = program.GetMethod ("Main"); |
||||
Assert.IsNotNull (method); |
||||
|
||||
AssertCode (@"
|
||||
.locals init (System.Int32 V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldlen |
||||
IL_0002: conv.i4 |
||||
IL_0003: stloc.0 |
||||
IL_0004: ldloc.0 |
||||
IL_0005: ldc.i4.8 |
||||
IL_0006: bgt.s IL_0026 |
||||
IL_0008: ldloc.0 |
||||
IL_0009: ldc.i4.1 |
||||
IL_000a: sub |
||||
IL_000b: switch (IL_0032, IL_0034, IL_0038, IL_0034) |
||||
IL_0020: ldloc.0 |
||||
IL_0021: ldc.i4.8 |
||||
IL_0022: beq.s IL_0036 |
||||
IL_0024: br.s IL_0038 |
||||
IL_0026: ldloc.0 |
||||
IL_0027: ldc.i4.s 16 |
||||
IL_0029: beq.s IL_0036 |
||||
IL_002b: ldloc.0 |
||||
IL_002c: ldc.i4.s 32 |
||||
IL_002e: beq.s IL_0036 |
||||
IL_0030: br.s IL_0038 |
||||
IL_0032: ldc.i4.0 |
||||
IL_0033: ret |
||||
IL_0034: ldc.i4.1 |
||||
IL_0035: ret |
||||
IL_0036: ldc.i4.2 |
||||
IL_0037: ret |
||||
IL_0038: ldc.i4.s 42 |
||||
IL_003a: ret |
||||
", method);
|
||||
} |
||||
|
||||
[TestIL ("methodspecs.il")] |
||||
public void MethodSpec (ModuleDefinition module) |
||||
{ |
||||
var tamtam = module.GetType ("Tamtam"); |
||||
|
||||
var bar = tamtam.GetMethod ("Bar"); |
||||
Assert.IsNotNull (bar); |
||||
|
||||
AssertCode (@"
|
||||
.locals () |
||||
IL_0000: ldc.i4.2 |
||||
IL_0001: call System.Void Tamtam::Foo<System.Int32>(TFoo) |
||||
IL_0006: ret |
||||
", bar);
|
||||
} |
||||
|
||||
[TestModule ("catch.exe")] |
||||
public void NestedTryCatchFinally (ModuleDefinition module) |
||||
{ |
||||
var program = module.GetType ("Program"); |
||||
var main = program.GetMethod ("Main"); |
||||
Assert.IsNotNull (main); |
||||
|
||||
AssertCode (@"
|
||||
.locals () |
||||
IL_0000: call System.Void Program::Foo() |
||||
IL_0005: leave.s IL_000d |
||||
IL_0007: call System.Void Program::Baz() |
||||
IL_000c: endfinally |
||||
IL_000d: leave.s IL_001f |
||||
IL_000f: pop |
||||
IL_0010: call System.Void Program::Bar() |
||||
IL_0015: leave.s IL_001f |
||||
IL_0017: pop |
||||
IL_0018: call System.Void Program::Bar() |
||||
IL_001d: leave.s IL_001f |
||||
IL_001f: leave.s IL_0027 |
||||
IL_0021: call System.Void Program::Baz() |
||||
IL_0026: endfinally |
||||
IL_0027: ret |
||||
.try IL_0000 to IL_0007 finally handler IL_0007 to IL_000d |
||||
.try IL_0000 to IL_000f catch System.ArgumentException handler IL_000f to IL_0017 |
||||
.try IL_0000 to IL_000f catch System.Exception handler IL_0017 to IL_001f |
||||
.try IL_0000 to IL_0021 finally handler IL_0021 to IL_0027 |
||||
", main);
|
||||
} |
||||
|
||||
[TestModule ("fptr.exe", Verify = false)] |
||||
public void FunctionPointersAndCallSites (ModuleDefinition module) |
||||
{ |
||||
var type = module.Types [0]; |
||||
var start = type.GetMethod ("Start"); |
||||
Assert.IsNotNull (start); |
||||
|
||||
AssertCode (@"
|
||||
.locals init () |
||||
IL_0000: ldc.i4.1 |
||||
IL_0001: call method System.Int32 *(System.Int32) MakeDecision::Decide() |
||||
IL_0006: calli System.Int32(System.Int32) |
||||
IL_000b: call System.Void System.Console::WriteLine(System.Int32) |
||||
IL_0010: ldc.i4.1 |
||||
IL_0011: call method System.Int32 *(System.Int32) MakeDecision::Decide() |
||||
IL_0016: calli System.Int32(System.Int32) |
||||
IL_001b: call System.Void System.Console::WriteLine(System.Int32) |
||||
IL_0020: ldc.i4.1 |
||||
IL_0021: call method System.Int32 *(System.Int32) MakeDecision::Decide() |
||||
IL_0026: calli System.Int32(System.Int32) |
||||
IL_002b: call System.Void System.Console::WriteLine(System.Int32) |
||||
IL_0030: ret |
||||
", start);
|
||||
} |
||||
|
||||
[TestIL ("hello.il")] |
||||
public void ThisParameter (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Foo"); |
||||
var method = type.GetMethod ("Gazonk"); |
||||
|
||||
Assert.IsNotNull (method); |
||||
|
||||
AssertCode (@"
|
||||
.locals () |
||||
IL_0000: ldarg 0 |
||||
IL_0004: pop |
||||
IL_0005: ret |
||||
", method);
|
||||
|
||||
Assert.AreEqual (method.Body.ThisParameter, method.Body.Instructions [0].Operand); |
||||
} |
||||
|
||||
[TestIL ("hello.il")] |
||||
public void FilterMaxStack (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Foo"); |
||||
var method = type.GetMethod ("TestFilter"); |
||||
|
||||
Assert.IsNotNull (method); |
||||
Assert.AreEqual (2, method.Body.MaxStackSize); |
||||
} |
||||
|
||||
[TestModule ("iterator.exe")] |
||||
public void Iterator (ModuleDefinition module) |
||||
{ |
||||
var method = module.GetType ("Program").GetMethod ("GetLittleArgs"); |
||||
Assert.IsNotNull (method.Body); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void LoadString (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("FooAttribute"); |
||||
var get_fiou = type.GetMethod ("get_Fiou"); |
||||
Assert.IsNotNull (get_fiou); |
||||
|
||||
var ldstr = get_fiou.Body.Instructions.Where (i => i.OpCode == OpCodes.Ldstr).First (); |
||||
Assert.AreEqual ("fiou", ldstr.Operand); |
||||
} |
||||
|
||||
static void AssertCode (string expected, MethodDefinition method) |
||||
{ |
||||
Assert.IsTrue (method.HasBody); |
||||
Assert.IsNotNull (method.Body); |
||||
|
||||
Assert.AreEqual (Normalize (expected), Normalize (Formatter.FormatMethodBody (method))); |
||||
} |
||||
|
||||
static string Normalize (string str) |
||||
{ |
||||
return str.Trim ().Replace ("\r\n", "\n"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddInstruction () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
|
||||
var first = il.Create (OpCodes.Nop); |
||||
var second = il.Create (OpCodes.Nop); |
||||
|
||||
body.Instructions.Add (first); |
||||
body.Instructions.Add (second); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (second, first.Next); |
||||
Assert.AreEqual (first, second.Previous); |
||||
Assert.IsNull (second.Next); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertInstruction () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
|
||||
var first = il.Create (OpCodes.Nop); |
||||
var second = il.Create (OpCodes.Nop); |
||||
var third = il.Create (OpCodes.Nop); |
||||
|
||||
body.Instructions.Add (first); |
||||
body.Instructions.Add (third); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (third, first.Next); |
||||
Assert.AreEqual (first, third.Previous); |
||||
Assert.IsNull (third.Next); |
||||
|
||||
body.Instructions.Insert (1, second); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (second, first.Next); |
||||
Assert.AreEqual (first, second.Previous); |
||||
Assert.AreEqual (third, second.Next); |
||||
Assert.AreEqual (second, third.Previous); |
||||
Assert.IsNull (third.Next); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertAfterLastInstruction () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
|
||||
var first = il.Create (OpCodes.Nop); |
||||
var second = il.Create (OpCodes.Nop); |
||||
var third = il.Create (OpCodes.Nop); |
||||
|
||||
body.Instructions.Add (first); |
||||
body.Instructions.Add (second); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (second, first.Next); |
||||
Assert.AreEqual (first, second.Previous); |
||||
Assert.IsNull (second.Next); |
||||
|
||||
body.Instructions.Insert (2, third); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (second, first.Next); |
||||
Assert.AreEqual (first, second.Previous); |
||||
Assert.AreEqual (third, second.Next); |
||||
Assert.AreEqual (second, third.Previous); |
||||
Assert.IsNull (third.Next); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveInstruction () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var il = body.GetILProcessor (); |
||||
|
||||
var first = il.Create (OpCodes.Nop); |
||||
var second = il.Create (OpCodes.Nop); |
||||
var third = il.Create (OpCodes.Nop); |
||||
|
||||
body.Instructions.Add (first); |
||||
body.Instructions.Add (second); |
||||
body.Instructions.Add (third); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (second, first.Next); |
||||
Assert.AreEqual (first, second.Previous); |
||||
Assert.AreEqual (third, second.Next); |
||||
Assert.AreEqual (second, third.Previous); |
||||
Assert.IsNull (third.Next); |
||||
|
||||
body.Instructions.Remove (second); |
||||
|
||||
Assert.IsNull (first.Previous); |
||||
Assert.AreEqual (third, first.Next); |
||||
Assert.AreEqual (first, third.Previous); |
||||
Assert.IsNull (third.Next); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,193 @@
@@ -0,0 +1,193 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class MethodTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("Methods.cs")] |
||||
public void AbstractMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.Types [1]; |
||||
Assert.AreEqual ("Foo", type.Name); |
||||
Assert.AreEqual (2, type.Methods.Count); |
||||
|
||||
var method = type.GetMethod ("Bar"); |
||||
Assert.AreEqual ("Bar", method.Name); |
||||
Assert.IsTrue (method.IsAbstract); |
||||
Assert.IsNotNull (method.ReturnType); |
||||
|
||||
Assert.AreEqual (1, method.Parameters.Count); |
||||
|
||||
var parameter = method.Parameters [0]; |
||||
|
||||
Assert.AreEqual ("a", parameter.Name); |
||||
Assert.AreEqual ("System.Int32", parameter.ParameterType.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("Methods.cs")] |
||||
public void SimplePInvoke (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar"); |
||||
var pan = bar.GetMethod ("Pan"); |
||||
|
||||
Assert.IsTrue (pan.IsPInvokeImpl); |
||||
Assert.IsNotNull (pan.PInvokeInfo); |
||||
|
||||
Assert.AreEqual ("Pan", pan.PInvokeInfo.EntryPoint); |
||||
Assert.IsNotNull (pan.PInvokeInfo.Module); |
||||
Assert.AreEqual ("foo.dll", pan.PInvokeInfo.Module.Name); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericMethodDefinition (ModuleDefinition module) |
||||
{ |
||||
var baz = module.GetType ("Baz"); |
||||
|
||||
var gazonk = baz.GetMethod ("Gazonk"); |
||||
|
||||
Assert.IsNotNull (gazonk); |
||||
|
||||
Assert.IsTrue (gazonk.HasGenericParameters); |
||||
Assert.AreEqual (1, gazonk.GenericParameters.Count); |
||||
Assert.AreEqual ("TBang", gazonk.GenericParameters [0].Name); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void ReturnGenericInstance (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar`1"); |
||||
|
||||
var self = bar.GetMethod ("Self"); |
||||
Assert.IsNotNull (self); |
||||
|
||||
var bar_t = self.ReturnType; |
||||
|
||||
Assert.IsTrue (bar_t.IsGenericInstance); |
||||
|
||||
var bar_t_instance = (GenericInstanceType) bar_t; |
||||
|
||||
Assert.AreEqual (bar.GenericParameters [0], bar_t_instance.GenericArguments [0]); |
||||
|
||||
var self_str = bar.GetMethod ("SelfString"); |
||||
Assert.IsNotNull (self_str); |
||||
|
||||
var bar_str = self_str.ReturnType; |
||||
Assert.IsTrue (bar_str.IsGenericInstance); |
||||
|
||||
var bar_str_instance = (GenericInstanceType) bar_str; |
||||
|
||||
Assert.AreEqual ("System.String", bar_str_instance.GenericArguments [0].FullName); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void ReturnGenericInstanceWithMethodParameter (ModuleDefinition module) |
||||
{ |
||||
var baz = module.GetType ("Baz"); |
||||
|
||||
var gazoo = baz.GetMethod ("Gazoo"); |
||||
Assert.IsNotNull (gazoo); |
||||
|
||||
var bar_bingo = gazoo.ReturnType; |
||||
|
||||
Assert.IsTrue (bar_bingo.IsGenericInstance); |
||||
|
||||
var bar_bingo_instance = (GenericInstanceType) bar_bingo; |
||||
|
||||
Assert.AreEqual (gazoo.GenericParameters [0], bar_bingo_instance.GenericArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("Interfaces.cs")] |
||||
public void SimpleOverrides (ModuleDefinition module) |
||||
{ |
||||
var ibingo = module.GetType ("IBingo"); |
||||
var ibingo_foo = ibingo.GetMethod ("Foo"); |
||||
Assert.IsNotNull (ibingo_foo); |
||||
|
||||
var ibingo_bar = ibingo.GetMethod ("Bar"); |
||||
Assert.IsNotNull (ibingo_bar); |
||||
|
||||
var bingo = module.GetType ("Bingo"); |
||||
|
||||
var foo = bingo.GetMethod ("IBingo.Foo"); |
||||
Assert.IsNotNull (foo); |
||||
|
||||
Assert.IsTrue (foo.HasOverrides); |
||||
Assert.AreEqual (ibingo_foo, foo.Overrides [0]); |
||||
|
||||
var bar = bingo.GetMethod ("IBingo.Bar"); |
||||
Assert.IsNotNull (bar); |
||||
|
||||
Assert.IsTrue (bar.HasOverrides); |
||||
Assert.AreEqual (ibingo_bar, bar.Overrides [0]); |
||||
} |
||||
|
||||
[TestModule ("varargs.exe")] |
||||
public void VarArgs (ModuleDefinition module) |
||||
{ |
||||
var module_type = module.Types [0]; |
||||
|
||||
Assert.AreEqual (3, module_type.Methods.Count); |
||||
|
||||
var bar = module_type.GetMethod ("Bar"); |
||||
var baz = module_type.GetMethod ("Baz"); |
||||
var foo = module_type.GetMethod ("Foo"); |
||||
|
||||
Assert.IsTrue (bar.IsVarArg ()); |
||||
Assert.IsFalse (baz.IsVarArg ()); |
||||
|
||||
Assert.IsTrue(foo.IsVarArg ()); |
||||
|
||||
var bar_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x000a).First ().Operand; |
||||
|
||||
Assert.IsTrue (bar_reference.IsVarArg ()); |
||||
Assert.AreEqual (0, bar_reference.GetSentinelPosition ()); |
||||
|
||||
var foo_reference = (MethodReference) baz.Body.Instructions.Where (i => i.Offset == 0x0023).First ().Operand; |
||||
|
||||
Assert.IsTrue (foo_reference.IsVarArg ()); |
||||
|
||||
Assert.AreEqual (1, foo_reference.GetSentinelPosition ()); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericInstanceMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("It"); |
||||
var method = type.GetMethod ("ReadPwow"); |
||||
|
||||
GenericInstanceMethod instance = null; |
||||
|
||||
foreach (var instruction in method.Body.Instructions) { |
||||
instance = instruction.Operand as GenericInstanceMethod; |
||||
if (instance != null) |
||||
break; |
||||
} |
||||
|
||||
Assert.IsNotNull (instance); |
||||
|
||||
Assert.AreEqual (TokenType.MethodSpec, instance.MetadataToken.TokenType); |
||||
Assert.AreNotEqual (0, instance.MetadataToken.RID); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void MethodRefDeclaredOnGenerics (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Tamtam"); |
||||
var beta = type.GetMethod ("Beta"); |
||||
var charlie = type.GetMethod ("Charlie"); |
||||
|
||||
var new_list_beta = (MethodReference) beta.Body.Instructions [0].Operand; |
||||
var new_list_charlie = (MethodReference) charlie.Body.Instructions [0].Operand; |
||||
|
||||
Assert.AreEqual ("System.Collections.Generic.List`1<TBeta>", new_list_beta.DeclaringType.FullName); |
||||
Assert.AreEqual ("System.Collections.Generic.List`1<TCharlie>", new_list_charlie.DeclaringType.FullName); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,250 @@
@@ -0,0 +1,250 @@
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ModuleTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void CreateModuleEscapesAssemblyName () |
||||
{ |
||||
var module = ModuleDefinition.CreateModule ("Test.dll", ModuleKind.Dll); |
||||
Assert.AreEqual ("Test", module.Assembly.Name.Name); |
||||
|
||||
module = ModuleDefinition.CreateModule ("Test.exe", ModuleKind.Console); |
||||
Assert.AreEqual ("Test", module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void SingleModule (ModuleDefinition module) |
||||
{ |
||||
var assembly = module.Assembly; |
||||
|
||||
Assert.AreEqual (1, assembly.Modules.Count); |
||||
Assert.IsNotNull (assembly.MainModule); |
||||
} |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void EntryPoint (ModuleDefinition module) |
||||
{ |
||||
var entry_point = module.EntryPoint; |
||||
Assert.IsNotNull (entry_point); |
||||
|
||||
Assert.AreEqual ("System.Void Program::Main()", entry_point.ToString ()); |
||||
} |
||||
|
||||
[TestModule ("mma.exe")] |
||||
public void MultiModules (ModuleDefinition module) |
||||
{ |
||||
var assembly = module.Assembly; |
||||
|
||||
Assert.AreEqual (3, assembly.Modules.Count); |
||||
|
||||
Assert.AreEqual ("mma.exe", assembly.Modules [0].Name); |
||||
Assert.AreEqual (ModuleKind.Console, assembly.Modules [0].Kind); |
||||
|
||||
Assert.AreEqual ("moda.netmodule", assembly.Modules [1].Name); |
||||
Assert.AreEqual ("eedb4721-6c3e-4d9a-be30-49021121dd92", assembly.Modules [1].Mvid.ToString ()); |
||||
Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [1].Kind); |
||||
|
||||
Assert.AreEqual ("modb.netmodule", assembly.Modules [2].Name); |
||||
Assert.AreEqual ("46c5c577-11b2-4ea0-bb3c-3c71f1331dd0", assembly.Modules [2].Mvid.ToString ()); |
||||
Assert.AreEqual (ModuleKind.NetModule, assembly.Modules [2].Kind); |
||||
} |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void ModuleInformation (ModuleDefinition module) |
||||
{ |
||||
Assert.IsNotNull (module); |
||||
|
||||
Assert.AreEqual ("hello.exe", module.Name); |
||||
Assert.AreEqual (new Guid ("C3BC2BD3-2576-4D00-A80E-465B5632415F"), module.Mvid); |
||||
} |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void AssemblyReferences (ModuleDefinition module) |
||||
{ |
||||
Assert.AreEqual (1, module.AssemblyReferences.Count); |
||||
|
||||
var reference = module.AssemblyReferences [0]; |
||||
|
||||
Assert.AreEqual ("mscorlib", reference.Name); |
||||
Assert.AreEqual (new Version (2, 0, 0, 0), reference.Version); |
||||
Assert.AreEqual (new byte [] { 0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89 }, reference.PublicKeyToken); |
||||
} |
||||
|
||||
[TestModule ("pinvoke.exe")] |
||||
public void ModuleReferences (ModuleDefinition module) |
||||
{ |
||||
Assert.AreEqual (2, module.ModuleReferences.Count); |
||||
Assert.AreEqual ("kernel32.dll", module.ModuleReferences [0].Name); |
||||
Assert.AreEqual ("shell32.dll", module.ModuleReferences [1].Name); |
||||
} |
||||
|
||||
[TestModule ("hello.exe")] |
||||
public void Types (ModuleDefinition module) |
||||
{ |
||||
Assert.AreEqual (2, module.Types.Count); |
||||
Assert.AreEqual ("<Module>", module.Types [0].FullName); |
||||
Assert.AreEqual ("<Module>", module.GetType ("<Module>").FullName); |
||||
Assert.AreEqual ("Program", module.Types [1].FullName); |
||||
Assert.AreEqual ("Program", module.GetType ("Program").FullName); |
||||
} |
||||
|
||||
[TestModule ("libres.dll")] |
||||
public void LinkedResource (ModuleDefinition module) |
||||
{ |
||||
var resource = module.Resources.Where (res => res.Name == "linked.txt").First () as LinkedResource; |
||||
Assert.IsNotNull (resource); |
||||
|
||||
Assert.AreEqual ("linked.txt", resource.Name); |
||||
Assert.AreEqual ("linked.txt", resource.File); |
||||
Assert.AreEqual (ResourceType.Linked, resource.ResourceType); |
||||
Assert.IsTrue (resource.IsPublic); |
||||
} |
||||
|
||||
[TestModule ("libres.dll")] |
||||
public void EmbeddedResource (ModuleDefinition module) |
||||
{ |
||||
var resource = module.Resources.Where (res => res.Name == "embedded1.txt").First () as EmbeddedResource; |
||||
Assert.IsNotNull (resource); |
||||
|
||||
Assert.AreEqual ("embedded1.txt", resource.Name); |
||||
Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); |
||||
Assert.IsTrue (resource.IsPublic); |
||||
|
||||
using (var reader = new StreamReader (resource.GetResourceStream ())) |
||||
Assert.AreEqual ("Hello", reader.ReadToEnd ()); |
||||
|
||||
resource = module.Resources.Where (res => res.Name == "embedded2.txt").First () as EmbeddedResource; |
||||
Assert.IsNotNull (resource); |
||||
|
||||
Assert.AreEqual ("embedded2.txt", resource.Name); |
||||
Assert.AreEqual (ResourceType.Embedded, resource.ResourceType); |
||||
Assert.IsTrue (resource.IsPublic); |
||||
|
||||
using (var reader = new StreamReader (resource.GetResourceStream ())) |
||||
Assert.AreEqual ("World", reader.ReadToEnd ()); |
||||
} |
||||
|
||||
[TestModule ("mma.exe")] |
||||
public void ExportedTypeFromNetModule (ModuleDefinition module) |
||||
{ |
||||
Assert.IsTrue (module.HasExportedTypes); |
||||
Assert.AreEqual (2, module.ExportedTypes.Count); |
||||
|
||||
var exported_type = module.ExportedTypes [0]; |
||||
|
||||
Assert.AreEqual ("Module.A.Foo", exported_type.FullName); |
||||
Assert.AreEqual ("moda.netmodule", exported_type.Scope.Name); |
||||
|
||||
exported_type = module.ExportedTypes [1]; |
||||
|
||||
Assert.AreEqual ("Module.B.Baz", exported_type.FullName); |
||||
Assert.AreEqual ("modb.netmodule", exported_type.Scope.Name); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void NestedTypeForwarder (ModuleDefinition module) |
||||
{ |
||||
Assert.IsTrue (module.HasExportedTypes); |
||||
Assert.AreEqual (2, module.ExportedTypes.Count); |
||||
|
||||
var exported_type = module.ExportedTypes [0]; |
||||
|
||||
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", exported_type.FullName); |
||||
Assert.AreEqual ("mscorlib", exported_type.Scope.Name); |
||||
Assert.IsTrue (exported_type.IsForwarder); |
||||
|
||||
var nested_exported_type = module.ExportedTypes [1]; |
||||
|
||||
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", nested_exported_type.FullName); |
||||
Assert.AreEqual (exported_type, nested_exported_type.DeclaringType); |
||||
Assert.AreEqual ("mscorlib", nested_exported_type.Scope.Name); |
||||
} |
||||
|
||||
[TestCSharp ("CustomAttributes.cs")] |
||||
public void HasTypeReference (ModuleDefinition module) |
||||
{ |
||||
Assert.IsTrue (module.HasTypeReference ("System.Attribute")); |
||||
Assert.IsTrue (module.HasTypeReference ("mscorlib", "System.Attribute")); |
||||
|
||||
Assert.IsFalse (module.HasTypeReference ("System.Core", "System.Attribute")); |
||||
Assert.IsFalse (module.HasTypeReference ("System.Linq.Enumerable")); |
||||
} |
||||
|
||||
[TestModule ("libhello.dll")] |
||||
public void Win32FileVersion (ModuleDefinition module) |
||||
{ |
||||
var version = FileVersionInfo.GetVersionInfo (module.FullyQualifiedName); |
||||
|
||||
Assert.AreEqual ("0.0.0.0", version.FileVersion); |
||||
} |
||||
|
||||
[TestModule ("noblob.dll")] |
||||
public void ModuleWithoutBlob (ModuleDefinition module) |
||||
{ |
||||
Assert.IsNull (module.Image.BlobHeap); |
||||
} |
||||
|
||||
[Test] |
||||
public void MixedModeModule () |
||||
{ |
||||
var module = GetResourceModule ("cppcli.dll"); |
||||
|
||||
Assert.AreEqual (1, module.ModuleReferences.Count); |
||||
Assert.AreEqual (string.Empty, module.ModuleReferences [0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
[ExpectedException (typeof (BadImageFormatException))] |
||||
public void OpenIrrelevantFile () |
||||
{ |
||||
GetResourceModule ("text_file.txt"); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteModuleTwice () |
||||
{ |
||||
var module = GetResourceModule ("iterator.exe"); |
||||
|
||||
var path = Path.Combine (Path.GetTempPath (), "cecil"); |
||||
var file = Path.Combine (path, "iteratorrt.exe"); |
||||
|
||||
module.Write (file); |
||||
module.Write (file); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTypeNamespacePlusName () |
||||
{ |
||||
var module = GetResourceModule ("moda.netmodule"); |
||||
|
||||
var type = module.GetType ("Module.A", "Foo"); |
||||
Assert.IsNotNull (type); |
||||
} |
||||
|
||||
[Test] |
||||
public void OpenModuleImmediate () |
||||
{ |
||||
var module = GetResourceModule ("hello.exe", ReadingMode.Immediate); |
||||
|
||||
Assert.AreEqual (ReadingMode.Immediate, module.ReadingMode); |
||||
} |
||||
|
||||
[Test] |
||||
public void OpenModuleDeferred () |
||||
{ |
||||
var module = GetResourceModule ("hello.exe", ReadingMode.Deferred); |
||||
|
||||
Assert.AreEqual (ReadingMode.Deferred, module.ReadingMode); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
using System; |
||||
|
||||
using Mono.Cecil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class NestedTypesTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("NestedTypes.cs")] |
||||
public void NestedTypes (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
|
||||
Assert.AreEqual ("Foo", foo.Name); |
||||
Assert.AreEqual ("Foo", foo.FullName); |
||||
Assert.AreEqual (module, foo.Module); |
||||
Assert.AreEqual (1, foo.NestedTypes.Count); |
||||
|
||||
var bar = foo.NestedTypes [0]; |
||||
|
||||
Assert.AreEqual ("Bar", bar.Name); |
||||
Assert.AreEqual ("Foo/Bar", bar.FullName); |
||||
Assert.AreEqual (module, bar.Module); |
||||
Assert.AreEqual (1, bar.NestedTypes.Count); |
||||
|
||||
var baz = bar.NestedTypes [0]; |
||||
|
||||
Assert.AreEqual ("Baz", baz.Name); |
||||
Assert.AreEqual ("Foo/Bar/Baz", baz.FullName); |
||||
Assert.AreEqual (module, baz.Module); |
||||
} |
||||
|
||||
[TestCSharp ("NestedTypes.cs")] |
||||
public void DirectNestedType (ModuleDefinition module) |
||||
{ |
||||
var bingo = module.GetType ("Bingo"); |
||||
var get_fuel = bingo.GetMethod ("GetFuel"); |
||||
|
||||
Assert.AreEqual ("Bingo/Fuel", get_fuel.ReturnType.FullName); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,224 @@
@@ -0,0 +1,224 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ParameterTests : BaseTestFixture { |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void MarshalAsI4 (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar"); |
||||
var pan = bar.GetMethod ("Pan"); |
||||
|
||||
Assert.AreEqual (1, pan.Parameters.Count); |
||||
|
||||
var parameter = pan.Parameters [0]; |
||||
|
||||
Assert.IsTrue (parameter.HasMarshalInfo); |
||||
var info = parameter.MarshalInfo; |
||||
|
||||
Assert.AreEqual (typeof (MarshalInfo), info.GetType ()); |
||||
Assert.AreEqual (NativeType.I4, info.NativeType); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void CustomMarshaler (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar"); |
||||
var pan = bar.GetMethod ("PanPan"); |
||||
|
||||
var parameter = pan.Parameters [0]; |
||||
|
||||
Assert.IsTrue (parameter.HasMarshalInfo); |
||||
|
||||
var info = (CustomMarshalInfo) parameter.MarshalInfo; |
||||
|
||||
Assert.AreEqual (Guid.Empty, info.Guid); |
||||
Assert.AreEqual (string.Empty, info.UnmanagedType); |
||||
Assert.AreEqual (NativeType.CustomMarshaler, info.NativeType); |
||||
Assert.AreEqual ("nomnom", info.Cookie); |
||||
|
||||
Assert.AreEqual ("Boc", info.ManagedType.FullName); |
||||
Assert.AreEqual (module, info.ManagedType.Scope); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void SafeArrayMarshaler (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar"); |
||||
var pan = bar.GetMethod ("PanPan"); |
||||
|
||||
Assert.IsTrue (pan.MethodReturnType.HasMarshalInfo); |
||||
|
||||
var info = (SafeArrayMarshalInfo) pan.MethodReturnType.MarshalInfo; |
||||
|
||||
Assert.AreEqual (VariantType.Dispatch, info.ElementType); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void ArrayMarshaler (ModuleDefinition module) |
||||
{ |
||||
var bar = module.GetType ("Bar"); |
||||
var pan = bar.GetMethod ("PanPan"); |
||||
|
||||
var parameter = pan.Parameters [1]; |
||||
|
||||
Assert.IsTrue (parameter.HasMarshalInfo); |
||||
|
||||
var info = (ArrayMarshalInfo) parameter.MarshalInfo; |
||||
|
||||
Assert.AreEqual (NativeType.I8, info.ElementType); |
||||
Assert.AreEqual (66, info.Size); |
||||
Assert.AreEqual (2, info.SizeParameterIndex); |
||||
|
||||
parameter = pan.Parameters [3]; |
||||
|
||||
Assert.IsTrue (parameter.HasMarshalInfo); |
||||
|
||||
info = (ArrayMarshalInfo) parameter.MarshalInfo; |
||||
|
||||
Assert.AreEqual (NativeType.I2, info.ElementType); |
||||
Assert.AreEqual (-1, info.Size); |
||||
Assert.AreEqual (-1, info.SizeParameterIndex); |
||||
} |
||||
|
||||
[TestModule ("marshal.dll")] |
||||
public void ArrayMarshalerSized (ModuleDefinition module) |
||||
{ |
||||
var delegate_type = module.GetType ("SomeMethod"); |
||||
var parameter = delegate_type.GetMethod ("Invoke").Parameters [1]; |
||||
|
||||
Assert.IsTrue (parameter.HasMarshalInfo); |
||||
var array_info = (ArrayMarshalInfo) parameter.MarshalInfo; |
||||
|
||||
Assert.IsNotNull (array_info); |
||||
|
||||
Assert.AreEqual (0, array_info.SizeParameterMultiplier); |
||||
} |
||||
|
||||
[TestModule ("boxedoptarg.dll")] |
||||
public void BoxedDefaultArgumentValue (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
var bar = foo.GetMethod ("Bar"); |
||||
var baz = bar.Parameters [0]; |
||||
|
||||
Assert.IsTrue (baz.HasConstant); |
||||
Assert.AreEqual (-1, baz.Constant); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddParameterIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
|
||||
var x = new ParameterDefinition ("x", ParameterAttributes.None, object_ref); |
||||
var y = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
|
||||
method.Parameters.Add (x); |
||||
method.Parameters.Add (y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
|
||||
Assert.AreEqual (method, x.Method); |
||||
Assert.AreEqual (method, y.Method); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveAtParameterIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
|
||||
var x = new ParameterDefinition ("x", ParameterAttributes.None, object_ref); |
||||
var y = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
var z = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
|
||||
method.Parameters.Add (x); |
||||
method.Parameters.Add (y); |
||||
method.Parameters.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
|
||||
method.Parameters.RemoveAt (1); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveParameterIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
|
||||
var x = new ParameterDefinition ("x", ParameterAttributes.None, object_ref); |
||||
var y = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
var z = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
|
||||
method.Parameters.Add (x); |
||||
method.Parameters.Add (y); |
||||
method.Parameters.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
|
||||
method.Parameters.Remove (y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertParameterIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
|
||||
var x = new ParameterDefinition ("x", ParameterAttributes.None, object_ref); |
||||
var y = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
var z = new ParameterDefinition ("y", ParameterAttributes.None, object_ref); |
||||
|
||||
method.Parameters.Add (x); |
||||
method.Parameters.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
|
||||
method.Parameters.Insert (1, y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
} |
||||
|
||||
[TestIL ("hello.il")] |
||||
public void GenericParameterConstant (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
var method = foo.GetMethod ("GetState"); |
||||
|
||||
Assert.IsNotNull (method); |
||||
|
||||
var parameter = method.Parameters [1]; |
||||
|
||||
Assert.IsTrue (parameter.HasConstant); |
||||
Assert.IsNull (parameter.Constant); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,112 @@
@@ -0,0 +1,112 @@
|
||||
using System.Linq; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class PropertyTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("Properties.cs")] |
||||
public void AbstractMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Foo"); |
||||
|
||||
Assert.IsTrue (type.HasProperties); |
||||
|
||||
var properties = type.Properties; |
||||
|
||||
Assert.AreEqual (3, properties.Count); |
||||
|
||||
var property = properties [0]; |
||||
|
||||
Assert.IsNotNull (property); |
||||
Assert.AreEqual ("Bar", property.Name); |
||||
Assert.IsNotNull (property.PropertyType); |
||||
Assert.AreEqual ("System.Int32", property.PropertyType.FullName); |
||||
|
||||
Assert.IsNotNull (property.GetMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); |
||||
Assert.IsNull (property.SetMethod); |
||||
|
||||
property = properties [1]; |
||||
|
||||
Assert.IsNotNull (property); |
||||
Assert.AreEqual ("Baz", property.Name); |
||||
Assert.IsNotNull (property.PropertyType); |
||||
Assert.AreEqual ("System.String", property.PropertyType.FullName); |
||||
|
||||
Assert.IsNotNull (property.GetMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes); |
||||
Assert.IsNotNull (property.SetMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); |
||||
|
||||
property = properties [2]; |
||||
|
||||
Assert.IsNotNull (property); |
||||
Assert.AreEqual ("Gazonk", property.Name); |
||||
Assert.IsNotNull (property.PropertyType); |
||||
Assert.AreEqual ("System.String", property.PropertyType.FullName); |
||||
|
||||
Assert.IsNull (property.GetMethod); |
||||
Assert.IsNotNull (property.SetMethod); |
||||
Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes); |
||||
} |
||||
|
||||
[TestIL ("others.il")] |
||||
public void OtherMethod (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Others"); |
||||
|
||||
Assert.IsTrue (type.HasProperties); |
||||
|
||||
var properties = type.Properties; |
||||
|
||||
Assert.AreEqual (1, properties.Count); |
||||
|
||||
var property = properties [0]; |
||||
|
||||
Assert.IsNotNull (property); |
||||
Assert.AreEqual ("Context", property.Name); |
||||
Assert.IsNotNull (property.PropertyType); |
||||
Assert.AreEqual ("System.String", property.PropertyType.FullName); |
||||
|
||||
Assert.IsTrue (property.HasOtherMethods); |
||||
|
||||
Assert.AreEqual (2, property.OtherMethods.Count); |
||||
|
||||
var other = property.OtherMethods [0]; |
||||
Assert.AreEqual ("let_Context", other.Name); |
||||
|
||||
other = property.OtherMethods [1]; |
||||
Assert.AreEqual ("bet_Context", other.Name); |
||||
} |
||||
|
||||
[TestCSharp ("Properties.cs")] |
||||
public void SetOnlyIndexer (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Bar"); |
||||
var indexer = type.Properties.Where (property => property.Name == "Item").First (); |
||||
|
||||
var parameters = indexer.Parameters; |
||||
|
||||
Assert.AreEqual (2, parameters.Count); |
||||
Assert.AreEqual ("System.Int32", parameters [0].ParameterType.FullName); |
||||
Assert.AreEqual ("System.String", parameters [1].ParameterType.FullName); |
||||
} |
||||
|
||||
[TestCSharp ("Properties.cs")] |
||||
public void ReadSemanticsFirst (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Baz"); |
||||
var setter = type.GetMethod ("set_Bingo"); |
||||
|
||||
Assert.AreEqual (MethodSemanticsAttributes.Setter, setter.SemanticsAttributes); |
||||
|
||||
var property = type.Properties.Where (p => p.Name == "Bingo").First (); |
||||
|
||||
Assert.AreEqual (setter, property.SetMethod); |
||||
Assert.AreEqual (type.GetMethod ("get_Bingo"), property.GetMethod); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,262 @@
@@ -0,0 +1,262 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class ResolveTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void StringEmpty () |
||||
{ |
||||
var string_empty = GetReference<Func<string>, FieldReference> ( |
||||
() => string.Empty); |
||||
|
||||
Assert.AreEqual ("System.String System.String::Empty", string_empty.FullName); |
||||
|
||||
var definition = string_empty.Resolve (); |
||||
|
||||
Assert.IsNotNull (definition); |
||||
|
||||
Assert.AreEqual ("System.String System.String::Empty", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
delegate string GetSubstring (string str, int start, int length); |
||||
|
||||
[Test] |
||||
public void StringSubstring () |
||||
{ |
||||
var string_substring = GetReference<GetSubstring, MethodReference> ( |
||||
(s, start, length) => s.Substring (start, length)); |
||||
|
||||
var definition = string_substring.Resolve (); |
||||
|
||||
Assert.IsNotNull (definition); |
||||
|
||||
Assert.AreEqual ("System.String System.String::Substring(System.Int32,System.Int32)", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void StringLength () |
||||
{ |
||||
var string_length = GetReference<Func<string, int>, MethodReference> (s => s.Length); |
||||
|
||||
var definition = string_length.Resolve (); |
||||
|
||||
Assert.IsNotNull (definition); |
||||
|
||||
Assert.AreEqual ("get_Length", definition.Name); |
||||
Assert.AreEqual ("System.String", definition.DeclaringType.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void ListOfStringAdd () |
||||
{ |
||||
var list_add = GetReference<Action<List<string>>, MethodReference> ( |
||||
list => list.Add ("coucou")); |
||||
|
||||
Assert.AreEqual ("System.Void System.Collections.Generic.List`1<System.String>::Add(!0)", list_add.FullName); |
||||
|
||||
var definition = list_add.Resolve (); |
||||
|
||||
Assert.IsNotNull (definition); |
||||
|
||||
Assert.AreEqual ("System.Void System.Collections.Generic.List`1::Add(T)", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void DictionaryOfStringTypeDefinitionTryGetValue () |
||||
{ |
||||
var try_get_value = GetReference<Func<Dictionary<string, TypeDefinition>, string, bool>, MethodReference> ( |
||||
(d, s) => { |
||||
TypeDefinition type; |
||||
return d.TryGetValue (s, out type); |
||||
}); |
||||
|
||||
Assert.AreEqual ("System.Boolean System.Collections.Generic.Dictionary`2<System.String,Mono.Cecil.TypeDefinition>::TryGetValue(!0,!1&)", |
||||
try_get_value.FullName); |
||||
|
||||
var definition = try_get_value.Resolve (); |
||||
|
||||
Assert.IsNotNull (definition); |
||||
|
||||
Assert.AreEqual ("System.Boolean System.Collections.Generic.Dictionary`2::TryGetValue(TKey,TValue&)", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
class CustomResolver : DefaultAssemblyResolver { |
||||
|
||||
public void Register (AssemblyDefinition assembly) |
||||
{ |
||||
this.RegisterAssembly (assembly); |
||||
this.AddSearchDirectory (Path.GetDirectoryName (assembly.MainModule.FullyQualifiedName)); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ExportedTypeFromModule () |
||||
{ |
||||
var resolver = new CustomResolver (); |
||||
var parameters = new ReaderParameters { AssemblyResolver = resolver }; |
||||
var mma = GetResourceModule ("mma.exe", parameters); |
||||
|
||||
resolver.Register (mma.Assembly); |
||||
|
||||
var current_module = GetCurrentModule (parameters); |
||||
var reference = new TypeReference ("Module.A", "Foo", current_module, AssemblyNameReference.Parse (mma.Assembly.FullName), false); |
||||
|
||||
var definition = reference.Resolve (); |
||||
Assert.IsNotNull (definition); |
||||
Assert.AreEqual ("Module.A.Foo", definition.FullName); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeForwarder () |
||||
{ |
||||
var resolver = new CustomResolver (); |
||||
var parameters = new ReaderParameters { AssemblyResolver = resolver }; |
||||
|
||||
var types = ModuleDefinition.ReadModule ( |
||||
CompilationService.CompileResource (GetCSharpResourcePath ("CustomAttributes.cs", typeof (ResolveTests).Assembly)), |
||||
parameters); |
||||
|
||||
resolver.Register (types.Assembly); |
||||
|
||||
var current_module = GetCurrentModule (parameters); |
||||
var reference = new TypeReference ("System.Diagnostics", "DebuggableAttribute", current_module, AssemblyNameReference.Parse (types.Assembly.FullName), false); |
||||
|
||||
var definition = reference.Resolve (); |
||||
Assert.IsNotNull (definition); |
||||
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void NestedTypeForwarder () |
||||
{ |
||||
var resolver = new CustomResolver (); |
||||
var parameters = new ReaderParameters { AssemblyResolver = resolver }; |
||||
|
||||
var types = ModuleDefinition.ReadModule ( |
||||
CompilationService.CompileResource (GetCSharpResourcePath ("CustomAttributes.cs", typeof (ResolveTests).Assembly)), |
||||
parameters); |
||||
|
||||
resolver.Register (types.Assembly); |
||||
|
||||
var current_module = GetCurrentModule (parameters); |
||||
var reference = new TypeReference ("", "DebuggingModes", current_module, null, true); |
||||
reference.DeclaringType = new TypeReference ("System.Diagnostics", "DebuggableAttribute", current_module, AssemblyNameReference.Parse (types.Assembly.FullName), false); |
||||
|
||||
var definition = reference.Resolve (); |
||||
Assert.IsNotNull (definition); |
||||
Assert.AreEqual ("System.Diagnostics.DebuggableAttribute/DebuggingModes", definition.FullName); |
||||
Assert.AreEqual ("mscorlib", definition.Module.Assembly.Name.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void RectangularArrayResolveGetMethod () |
||||
{ |
||||
var get_a_b = GetReference<Func<int[,], int>, MethodReference> (matrix => matrix [2, 2]); |
||||
|
||||
Assert.AreEqual ("Get", get_a_b.Name); |
||||
Assert.IsNotNull (get_a_b.Module); |
||||
Assert.IsNull (get_a_b.Resolve ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveFunctionPointer () |
||||
{ |
||||
var module = GetResourceModule ("cppcli.dll"); |
||||
var global = module.GetType ("<Module>"); |
||||
var field = global.GetField ("__onexitbegin_app_domain"); |
||||
|
||||
var type = field.FieldType as PointerType; |
||||
Assert.IsNotNull(type); |
||||
|
||||
var fnptr = type.ElementType as FunctionPointerType; |
||||
Assert.IsNotNull (fnptr); |
||||
|
||||
Assert.IsNull (fnptr.Resolve ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveGenericParameter () |
||||
{ |
||||
var collection = typeof (Mono.Collections.Generic.Collection<>).ToDefinition (); |
||||
var parameter = collection.GenericParameters [0]; |
||||
|
||||
Assert.IsNotNull (parameter); |
||||
|
||||
Assert.IsNull (parameter.Resolve ()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveNullVersionAssembly () |
||||
{ |
||||
var reference = AssemblyNameReference.Parse ("System.Core"); |
||||
reference.Version = null; |
||||
|
||||
var resolver = new DefaultAssemblyResolver (); |
||||
Assert.IsNotNull (resolver.Resolve (reference)); |
||||
} |
||||
|
||||
static TRet GetReference<TDel, TRet> (TDel code) |
||||
{ |
||||
var @delegate = code as Delegate; |
||||
if (@delegate == null) |
||||
throw new InvalidOperationException (); |
||||
|
||||
var reference = (TRet) GetReturnee (GetMethodFromDelegate (@delegate)); |
||||
|
||||
Assert.IsNotNull (reference); |
||||
|
||||
return reference; |
||||
} |
||||
|
||||
static object GetReturnee (MethodDefinition method) |
||||
{ |
||||
Assert.IsTrue (method.HasBody); |
||||
|
||||
var instruction = method.Body.Instructions [method.Body.Instructions.Count - 1]; |
||||
|
||||
Assert.IsNotNull (instruction); |
||||
|
||||
while (instruction != null) { |
||||
var opcode = instruction.OpCode; |
||||
switch (opcode.OperandType) { |
||||
case OperandType.InlineField: |
||||
case OperandType.InlineTok: |
||||
case OperandType.InlineType: |
||||
case OperandType.InlineMethod: |
||||
return instruction.Operand; |
||||
default: |
||||
instruction = instruction.Previous; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
throw new InvalidOperationException (); |
||||
} |
||||
|
||||
static MethodDefinition GetMethodFromDelegate (Delegate @delegate) |
||||
{ |
||||
var method = @delegate.Method; |
||||
var type = (TypeDefinition) TypeParser.ParseType (GetCurrentModule (), method.DeclaringType.FullName); |
||||
|
||||
Assert.IsNotNull (type); |
||||
|
||||
return type.Methods.Where (m => m.Name == method.Name).First (); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,290 @@
@@ -0,0 +1,290 @@
|
||||
using System; |
||||
using System.Globalization; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Metadata; |
||||
using Mono.Cecil.PE; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class SecurityDeclarationTests : BaseTestFixture { |
||||
|
||||
[TestModule ("decsec-xml.dll")] |
||||
public void XmlSecurityDeclaration (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("SubLibrary"); |
||||
|
||||
Assert.IsTrue (type.HasSecurityDeclarations); |
||||
|
||||
Assert.AreEqual (1, type.SecurityDeclarations.Count); |
||||
|
||||
var declaration = type.SecurityDeclarations [0]; |
||||
Assert.AreEqual (SecurityAction.Deny, declaration.Action); |
||||
|
||||
Assert.AreEqual (1, declaration.SecurityAttributes.Count); |
||||
|
||||
var attribute = declaration.SecurityAttributes [0]; |
||||
|
||||
Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); |
||||
|
||||
Assert.AreEqual (1, attribute.Properties.Count); |
||||
|
||||
var named_argument = attribute.Properties [0]; |
||||
|
||||
Assert.AreEqual ("XML", named_argument.Name); |
||||
|
||||
var argument = named_argument.Argument; |
||||
|
||||
Assert.AreEqual ("System.String", argument.Type.FullName); |
||||
|
||||
const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" |
||||
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis" |
||||
+ "sions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture" |
||||
+ "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla" |
||||
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n"; |
||||
|
||||
Assert.AreEqual (permission_set, argument.Value); |
||||
} |
||||
|
||||
[TestModule ("decsec1-xml.dll")] |
||||
public void XmlNet_1_1SecurityDeclaration (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("SubLibrary"); |
||||
|
||||
Assert.IsTrue (type.HasSecurityDeclarations); |
||||
|
||||
Assert.AreEqual (1, type.SecurityDeclarations.Count); |
||||
|
||||
var declaration = type.SecurityDeclarations [0]; |
||||
Assert.AreEqual (SecurityAction.Deny, declaration.Action); |
||||
|
||||
Assert.AreEqual (1, declaration.SecurityAttributes.Count); |
||||
|
||||
var attribute = declaration.SecurityAttributes [0]; |
||||
|
||||
Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); |
||||
|
||||
Assert.AreEqual (1, attribute.Properties.Count); |
||||
|
||||
var named_argument = attribute.Properties [0]; |
||||
|
||||
Assert.AreEqual ("XML", named_argument.Name); |
||||
|
||||
var argument = named_argument.Argument; |
||||
|
||||
Assert.AreEqual ("System.String", argument.Type.FullName); |
||||
|
||||
const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" |
||||
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis" |
||||
+ "sions.SecurityPermission, mscorlib, Version=1.0.0.0, Culture" |
||||
+ "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla" |
||||
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n"; |
||||
|
||||
Assert.AreEqual (permission_set, argument.Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefineSecurityDeclarationByBlob () |
||||
{ |
||||
var file = Path.Combine(Path.GetTempPath(), "SecDecBlob.dll"); |
||||
var module = ModuleDefinition.CreateModule ("SecDecBlob.dll", new ModuleParameters { Kind = ModuleKind.Dll, Runtime = TargetRuntime.Net_2_0 }); |
||||
|
||||
const string permission_set = "<PermissionSet class=\"System.Security.PermissionSe" |
||||
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permis" |
||||
+ "sions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture" |
||||
+ "=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFla" |
||||
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n"; |
||||
|
||||
var declaration = new SecurityDeclaration (SecurityAction.Deny, Encoding.Unicode.GetBytes (permission_set)); |
||||
module.Assembly.SecurityDeclarations.Add (declaration); |
||||
|
||||
module.Write (file); |
||||
module = ModuleDefinition.ReadModule (file); |
||||
|
||||
declaration = module.Assembly.SecurityDeclarations [0]; |
||||
Assert.AreEqual (SecurityAction.Deny, declaration.Action); |
||||
Assert.AreEqual (1, declaration.SecurityAttributes.Count); |
||||
|
||||
var attribute = declaration.SecurityAttributes [0]; |
||||
Assert.AreEqual ("System.Security.Permissions.PermissionSetAttribute", attribute.AttributeType.FullName); |
||||
Assert.AreEqual (1, attribute.Properties.Count); |
||||
|
||||
var named_argument = attribute.Properties [0]; |
||||
Assert.AreEqual ("XML", named_argument.Name); |
||||
var argument = named_argument.Argument; |
||||
Assert.AreEqual ("System.String", argument.Type.FullName); |
||||
Assert.AreEqual (permission_set, argument.Value); |
||||
} |
||||
|
||||
[TestModule ("empty-decsec-att.dll")] |
||||
public void SecurityDeclarationWithoutAttributes (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("TestSecurityAction.ModalUITypeEditor"); |
||||
var method = type.GetMethod ("GetEditStyle"); |
||||
|
||||
Assert.IsNotNull (method); |
||||
|
||||
Assert.AreEqual (1, method.SecurityDeclarations.Count); |
||||
|
||||
var declaration = method.SecurityDeclarations [0]; |
||||
Assert.AreEqual (SecurityAction.LinkDemand, declaration.Action); |
||||
Assert.AreEqual (1, declaration.SecurityAttributes.Count); |
||||
|
||||
var attribute = declaration.SecurityAttributes [0]; |
||||
Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); |
||||
Assert.AreEqual (0, attribute.Fields.Count); |
||||
Assert.AreEqual (0, attribute.Properties.Count); |
||||
} |
||||
|
||||
[TestModule ("decsec-att.dll")] |
||||
public void AttributeSecurityDeclaration (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("SubLibrary"); |
||||
|
||||
Assert.IsTrue (type.HasSecurityDeclarations); |
||||
|
||||
Assert.AreEqual (1, type.SecurityDeclarations.Count); |
||||
|
||||
var declaration = type.SecurityDeclarations [0]; |
||||
Assert.AreEqual (SecurityAction.Deny, declaration.Action); |
||||
|
||||
Assert.AreEqual (1, declaration.SecurityAttributes.Count); |
||||
|
||||
var attribute = declaration.SecurityAttributes [0]; |
||||
|
||||
Assert.AreEqual ("System.Security.Permissions.SecurityPermissionAttribute", attribute.AttributeType.FullName); |
||||
|
||||
Assert.AreEqual (1, attribute.Properties.Count); |
||||
|
||||
var named_argument = attribute.Properties [0]; |
||||
|
||||
Assert.AreEqual ("UnmanagedCode", named_argument.Name); |
||||
|
||||
var argument = named_argument.Argument; |
||||
|
||||
Assert.AreEqual ("System.Boolean", argument.Type.FullName); |
||||
|
||||
Assert.AreEqual (true, argument.Value); |
||||
} |
||||
|
||||
static void AssertCustomAttributeArgument (string expected, CustomAttributeNamedArgument named_argument) |
||||
{ |
||||
AssertCustomAttributeArgument (expected, named_argument.Argument); |
||||
} |
||||
|
||||
static void AssertCustomAttributeArgument (string expected, CustomAttributeArgument argument) |
||||
{ |
||||
var result = new StringBuilder (); |
||||
PrettyPrint (argument, result); |
||||
|
||||
Assert.AreEqual (expected, result.ToString ()); |
||||
} |
||||
|
||||
static string PrettyPrint (CustomAttribute attribute) |
||||
{ |
||||
var signature = new StringBuilder (); |
||||
signature.Append (".ctor ("); |
||||
|
||||
for (int i = 0; i < attribute.ConstructorArguments.Count; i++) { |
||||
if (i > 0) |
||||
signature.Append (", "); |
||||
|
||||
PrettyPrint (attribute.ConstructorArguments [i], signature); |
||||
} |
||||
|
||||
signature.Append (")"); |
||||
return signature.ToString (); |
||||
} |
||||
|
||||
static void PrettyPrint (CustomAttributeArgument argument, StringBuilder signature) |
||||
{ |
||||
var value = argument.Value; |
||||
|
||||
signature.Append ("("); |
||||
|
||||
PrettyPrint (argument.Type, signature); |
||||
|
||||
signature.Append (":"); |
||||
|
||||
PrettyPrintValue (argument.Value, signature); |
||||
|
||||
signature.Append (")"); |
||||
} |
||||
|
||||
static void PrettyPrintValue (object value, StringBuilder signature) |
||||
{ |
||||
if (value == null) { |
||||
signature.Append ("null"); |
||||
return; |
||||
} |
||||
|
||||
var arguments = value as CustomAttributeArgument []; |
||||
if (arguments != null) { |
||||
signature.Append ("{"); |
||||
for (int i = 0; i < arguments.Length; i++) { |
||||
if (i > 0) |
||||
signature.Append (", "); |
||||
|
||||
PrettyPrint (arguments [i], signature); |
||||
} |
||||
signature.Append ("}"); |
||||
|
||||
return; |
||||
} |
||||
|
||||
switch (Type.GetTypeCode (value.GetType ())) { |
||||
case TypeCode.String: |
||||
signature.AppendFormat ("\"{0}\"", value); |
||||
break; |
||||
case TypeCode.Char: |
||||
signature.AppendFormat ("'{0}'", (char) value); |
||||
break; |
||||
default: |
||||
var formattable = value as IFormattable; |
||||
if (formattable != null) { |
||||
signature.Append (formattable.ToString (null, CultureInfo.InvariantCulture)); |
||||
return; |
||||
} |
||||
|
||||
if (value is CustomAttributeArgument) { |
||||
PrettyPrint ((CustomAttributeArgument) value, signature); |
||||
return; |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static void PrettyPrint (TypeReference type, StringBuilder signature) |
||||
{ |
||||
if (type.IsArray) { |
||||
ArrayType array = (ArrayType) type; |
||||
signature.AppendFormat ("{0}[]", array.ElementType.etype.ToString ()); |
||||
} else if (type.etype == ElementType.None) { |
||||
signature.Append (type.FullName); |
||||
} else |
||||
signature.Append (type.etype.ToString ()); |
||||
} |
||||
|
||||
static void AssertArgument<T> (T value, CustomAttributeNamedArgument named_argument) |
||||
{ |
||||
AssertArgument (value, named_argument.Argument); |
||||
} |
||||
|
||||
static void AssertArgument<T> (T value, CustomAttributeArgument argument) |
||||
{ |
||||
AssertArgument (typeof (T).FullName, (object) value, argument); |
||||
} |
||||
|
||||
static void AssertArgument (string type, object value, CustomAttributeArgument argument) |
||||
{ |
||||
Assert.AreEqual (type, argument.Type.FullName); |
||||
Assert.AreEqual (value, argument.Value); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,394 @@
@@ -0,0 +1,394 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class TypeParserTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void SimpleStringReference () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
var corlib = module.TypeSystem.Corlib; |
||||
|
||||
const string fullname = "System.String"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (corlib, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System", type.Namespace); |
||||
Assert.AreEqual ("String", type.Name); |
||||
Assert.AreEqual (MetadataType.String, type.MetadataType); |
||||
Assert.IsFalse (type.IsValueType); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleInt32Reference () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
var corlib = module.TypeSystem.Corlib; |
||||
|
||||
const string fullname = "System.Int32"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (corlib, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System", type.Namespace); |
||||
Assert.AreEqual ("Int32", type.Name); |
||||
Assert.AreEqual (MetadataType.Int32, type.MetadataType); |
||||
Assert.IsTrue (type.IsValueType); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleTypeDefinition () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
const string fullname = "Mono.Cecil.Tests.TypeParserTests"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (module, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("Mono.Cecil.Tests", type.Namespace); |
||||
Assert.AreEqual ("TypeParserTests", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void ByRefTypeReference () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
var corlib = module.TypeSystem.Corlib; |
||||
|
||||
const string fullname = "System.String&"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
Assert.IsInstanceOfType (typeof (ByReferenceType), type); |
||||
|
||||
type = ((ByReferenceType) type).ElementType; |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (corlib, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System", type.Namespace); |
||||
Assert.AreEqual ("String", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void FullyQualifiedTypeReference () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
var cecil = module.AssemblyReferences.Where (reference => reference.Name == "Mono.Cecil").First (); |
||||
|
||||
var fullname = "Mono.Cecil.TypeDefinition, " + cecil.FullName; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (cecil, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("Mono.Cecil", type.Namespace); |
||||
Assert.AreEqual ("TypeDefinition", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void OpenGenericType () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
var corlib = module.TypeSystem.Corlib; |
||||
|
||||
const string fullname = "System.Collections.Generic.Dictionary`2"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (corlib, type.Scope); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System.Collections.Generic", type.Namespace); |
||||
Assert.AreEqual ("Dictionary`2", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
Assert.AreEqual (2, type.GenericParameters.Count); |
||||
} |
||||
|
||||
public class ID {} |
||||
|
||||
[Test] |
||||
public void SimpleNestedType () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
const string fullname = "Mono.Cecil.Tests.TypeParserTests+ID"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual (module, type.Scope); |
||||
Assert.AreEqual ("", type.Namespace); |
||||
Assert.AreEqual ("ID", type.Name); |
||||
|
||||
Assert.AreEqual ("Mono.Cecil.Tests.TypeParserTests/ID", type.FullName); |
||||
Assert.AreEqual (fullname, TypeParser.ToParseable (type)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TripleNestedTypeWithScope () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
const string fullname = "Bingo.Foo`1+Bar`1+Baz`1, Bingo"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
Assert.AreEqual ("Bingo.Foo`1+Bar`1+Baz`1, Bingo, Culture=neutral, PublicKeyToken=null", TypeParser.ToParseable (type)); |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual ("Bingo", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("", type.Namespace); |
||||
Assert.AreEqual ("Baz`1", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
Assert.AreEqual (1, type.GenericParameters.Count); |
||||
|
||||
type = type.DeclaringType; |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual ("Bingo", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("", type.Namespace); |
||||
Assert.AreEqual ("Bar`1", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
Assert.AreEqual (1, type.GenericParameters.Count); |
||||
|
||||
type = type.DeclaringType; |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual ("Bingo", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("Bingo", type.Namespace); |
||||
Assert.AreEqual ("Foo`1", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
Assert.AreEqual (1, type.GenericParameters.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void Vector () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
const string fullname = "Bingo.Gazonk[], Bingo"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
Assert.AreEqual ("Bingo.Gazonk[], Bingo, Culture=neutral, PublicKeyToken=null", TypeParser.ToParseable (type)); |
||||
|
||||
var array = type as ArrayType; |
||||
Assert.IsNotNull (array); |
||||
Assert.AreEqual (1, array.Rank); |
||||
Assert.IsTrue (array.IsVector); |
||||
|
||||
type = array.ElementType; |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual ("Bingo", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("Bingo", type.Namespace); |
||||
Assert.AreEqual ("Gazonk", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThreeDimensionalArray () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
const string fullname = "Bingo.Gazonk[,,], Bingo"; |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
var array = type as ArrayType; |
||||
Assert.IsNotNull (array); |
||||
Assert.AreEqual (3, array.Rank); |
||||
Assert.IsFalse (array.IsVector); |
||||
|
||||
type = array.ElementType; |
||||
|
||||
Assert.IsNotNull (type); |
||||
Assert.AreEqual ("Bingo", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("Bingo", type.Namespace); |
||||
Assert.AreEqual ("Gazonk", type.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeReference), type); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericInstanceExternArguments () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
var fullname = string.Format ("System.Collections.Generic.Dictionary`2[[System.Int32, {0}],[System.String, {0}]]", |
||||
typeof (object).Assembly.FullName); |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
Assert.AreEqual (fullname, TypeParser.ToParseable (type)); |
||||
|
||||
var instance = type as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreEqual (2, instance.GenericArguments.Count); |
||||
Assert.AreEqual ("mscorlib", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System.Collections.Generic", type.Namespace); |
||||
Assert.AreEqual ("Dictionary`2", type.Name); |
||||
|
||||
type = instance.ElementType; |
||||
|
||||
Assert.AreEqual (2, type.GenericParameters.Count); |
||||
|
||||
var argument = instance.GenericArguments [0]; |
||||
Assert.AreEqual ("mscorlib", argument.Scope.Name); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("System", argument.Namespace); |
||||
Assert.AreEqual ("Int32", argument.Name); |
||||
|
||||
argument = instance.GenericArguments [1]; |
||||
Assert.AreEqual ("mscorlib", argument.Scope.Name); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("System", argument.Namespace); |
||||
Assert.AreEqual ("String", argument.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericInstanceMixedArguments () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
var fullname = string.Format ("System.Collections.Generic.Dictionary`2[Mono.Cecil.Tests.TypeParserTests,[System.String, {0}]]", |
||||
typeof (object).Assembly.FullName); |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
var instance = type as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreEqual (2, instance.GenericArguments.Count); |
||||
Assert.AreEqual ("mscorlib", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System.Collections.Generic", type.Namespace); |
||||
Assert.AreEqual ("Dictionary`2", type.Name); |
||||
|
||||
type = instance.ElementType; |
||||
|
||||
Assert.AreEqual (2, type.GenericParameters.Count); |
||||
|
||||
var argument = instance.GenericArguments [0]; |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), argument); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("Mono.Cecil.Tests", argument.Namespace); |
||||
Assert.AreEqual ("TypeParserTests", argument.Name); |
||||
|
||||
argument = instance.GenericArguments [1]; |
||||
Assert.AreEqual ("mscorlib", argument.Scope.Name); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("System", argument.Namespace); |
||||
Assert.AreEqual ("String", argument.Name); |
||||
} |
||||
|
||||
public class Foo<TX, TY> { |
||||
} |
||||
|
||||
public class Bar {} |
||||
|
||||
[Test] |
||||
public void GenericInstanceTwoNonFqArguments () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
var fullname = string.Format ("System.Collections.Generic.Dictionary`2[Mono.Cecil.Tests.TypeParserTests+Bar,Mono.Cecil.Tests.TypeParserTests+Bar], {0}", typeof (object).Assembly.FullName); |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
var instance = type as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreEqual (2, instance.GenericArguments.Count); |
||||
Assert.AreEqual ("mscorlib", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System.Collections.Generic", type.Namespace); |
||||
Assert.AreEqual ("Dictionary`2", type.Name); |
||||
|
||||
type = instance.ElementType; |
||||
|
||||
Assert.AreEqual (2, type.GenericParameters.Count); |
||||
|
||||
var argument = instance.GenericArguments [0]; |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("", argument.Namespace); |
||||
Assert.AreEqual ("Bar", argument.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), argument); |
||||
|
||||
argument = instance.GenericArguments [1]; |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("", argument.Namespace); |
||||
Assert.AreEqual ("Bar", argument.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), argument); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexGenericInstanceMixedArguments () |
||||
{ |
||||
var module = GetCurrentModule (); |
||||
|
||||
var fullname = string.Format ("System.Collections.Generic.Dictionary`2[[System.String, {0}],Mono.Cecil.Tests.TypeParserTests+Foo`2[Mono.Cecil.Tests.TypeParserTests,[System.Int32, {0}]]]", |
||||
typeof (object).Assembly.FullName); |
||||
|
||||
var type = TypeParser.ParseType (module, fullname); |
||||
|
||||
var instance = type as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreEqual (2, instance.GenericArguments.Count); |
||||
Assert.AreEqual ("mscorlib", type.Scope.Name); |
||||
Assert.AreEqual (module, type.Module); |
||||
Assert.AreEqual ("System.Collections.Generic", type.Namespace); |
||||
Assert.AreEqual ("Dictionary`2", type.Name); |
||||
|
||||
type = instance.ElementType; |
||||
|
||||
Assert.AreEqual (2, type.GenericParameters.Count); |
||||
|
||||
var argument = instance.GenericArguments [0]; |
||||
Assert.AreEqual ("mscorlib", argument.Scope.Name); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("System", argument.Namespace); |
||||
Assert.AreEqual ("String", argument.Name); |
||||
|
||||
argument = instance.GenericArguments [1]; |
||||
|
||||
instance = argument as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreEqual (2, instance.GenericArguments.Count); |
||||
Assert.AreEqual (module, instance.Module); |
||||
Assert.AreEqual ("Mono.Cecil.Tests.TypeParserTests/Foo`2", instance.ElementType.FullName); |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), instance.ElementType); |
||||
|
||||
argument = instance.GenericArguments [0]; |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("Mono.Cecil.Tests", argument.Namespace); |
||||
Assert.AreEqual ("TypeParserTests", argument.Name); |
||||
Assert.IsInstanceOfType (typeof (TypeDefinition), argument); |
||||
|
||||
argument = instance.GenericArguments [1]; |
||||
Assert.AreEqual ("mscorlib", argument.Scope.Name); |
||||
Assert.AreEqual (module, argument.Module); |
||||
Assert.AreEqual ("System", argument.Namespace); |
||||
Assert.AreEqual ("Int32", argument.Name); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,199 @@
@@ -0,0 +1,199 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
using Mono.Cecil.Metadata; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class TypeTests : BaseTestFixture { |
||||
|
||||
[TestCSharp ("Layouts.cs")] |
||||
public void TypeLayout (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo"); |
||||
Assert.IsNotNull (foo); |
||||
Assert.IsTrue (foo.IsValueType); |
||||
|
||||
Assert.IsTrue (foo.HasLayoutInfo); |
||||
Assert.AreEqual (16, foo.ClassSize); |
||||
|
||||
var babar = module.GetType ("Babar"); |
||||
Assert.IsNotNull (babar); |
||||
Assert.IsFalse (babar.IsValueType); |
||||
Assert.IsFalse (babar.HasLayoutInfo); |
||||
} |
||||
|
||||
[TestIL ("types.il")] |
||||
public void SimpleInterfaces (ModuleDefinition module) |
||||
{ |
||||
var ibaz = module.GetType ("IBaz"); |
||||
Assert.IsNotNull (ibaz); |
||||
|
||||
Assert.IsTrue (ibaz.HasInterfaces); |
||||
|
||||
var interfaces = ibaz.Interfaces; |
||||
|
||||
Assert.AreEqual (2, interfaces.Count); |
||||
|
||||
Assert.AreEqual ("IBar", interfaces [0].FullName); |
||||
Assert.AreEqual ("IFoo", interfaces [1].FullName); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericTypeDefinition (ModuleDefinition module) |
||||
{ |
||||
var foo = module.GetType ("Foo`2"); |
||||
Assert.IsNotNull (foo); |
||||
|
||||
Assert.IsTrue (foo.HasGenericParameters); |
||||
Assert.AreEqual (2, foo.GenericParameters.Count); |
||||
|
||||
var tbar = foo.GenericParameters [0]; |
||||
|
||||
Assert.AreEqual ("TBar", tbar.Name); |
||||
Assert.AreEqual (foo, tbar.Owner); |
||||
|
||||
var tbaz = foo.GenericParameters [1]; |
||||
|
||||
Assert.AreEqual ("TBaz", tbaz.Name); |
||||
Assert.AreEqual (foo, tbaz.Owner); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void ConstrainedGenericType (ModuleDefinition module) |
||||
{ |
||||
var bongo_t = module.GetType ("Bongo`1"); |
||||
Assert.IsNotNull (bongo_t); |
||||
|
||||
var t = bongo_t.GenericParameters [0]; |
||||
Assert.IsNotNull (t); |
||||
Assert.AreEqual ("T", t.Name); |
||||
|
||||
Assert.IsTrue (t.HasConstraints); |
||||
Assert.AreEqual (2, t.Constraints.Count); |
||||
|
||||
Assert.AreEqual ("Zap", t.Constraints [0].FullName); |
||||
Assert.AreEqual ("IZoom", t.Constraints [1].FullName); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericBaseType (ModuleDefinition module) |
||||
{ |
||||
var child = module.GetType ("Child`1"); |
||||
|
||||
var child_t = child.GenericParameters [0]; |
||||
Assert.IsNotNull (child_t); |
||||
|
||||
var instance = child.BaseType as GenericInstanceType; |
||||
Assert.IsNotNull (instance); |
||||
Assert.AreNotEqual (0, instance.MetadataToken.RID); |
||||
|
||||
Assert.AreEqual (child_t, instance.GenericArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericConstraintOnGenericParameter (ModuleDefinition module) |
||||
{ |
||||
var duel = module.GetType ("Duel`3"); |
||||
|
||||
Assert.AreEqual (3, duel.GenericParameters.Count); |
||||
|
||||
var t1 = duel.GenericParameters [0]; |
||||
var t2 = duel.GenericParameters [1]; |
||||
var t3 = duel.GenericParameters [2]; |
||||
|
||||
Assert.AreEqual (t1, t2.Constraints [0]); |
||||
Assert.AreEqual (t2, t3.Constraints [0]); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericForwardBaseType (ModuleDefinition module) |
||||
{ |
||||
var tamchild = module.GetType ("TamChild"); |
||||
|
||||
Assert.IsNotNull (tamchild); |
||||
Assert.IsNotNull (tamchild.BaseType); |
||||
|
||||
var generic_instance = tamchild.BaseType as GenericInstanceType; |
||||
|
||||
Assert.IsNotNull (generic_instance); |
||||
|
||||
Assert.AreEqual (1, generic_instance.GenericArguments.Count); |
||||
Assert.AreEqual (module.GetType ("Tamtam"), generic_instance.GenericArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void TypeExtentingGenericOfSelf (ModuleDefinition module) |
||||
{ |
||||
var rec_child = module.GetType ("RecChild"); |
||||
|
||||
Assert.IsNotNull (rec_child); |
||||
Assert.IsNotNull (rec_child.BaseType); |
||||
|
||||
var generic_instance = rec_child.BaseType as GenericInstanceType; |
||||
|
||||
Assert.IsNotNull (generic_instance); |
||||
|
||||
Assert.AreEqual (1, generic_instance.GenericArguments.Count); |
||||
Assert.AreEqual (rec_child, generic_instance.GenericArguments [0]); |
||||
} |
||||
|
||||
[TestCSharp ("Methods.cs")] |
||||
public void TypeReferenceValueType (ModuleDefinition module) |
||||
{ |
||||
var baz = module.GetType ("Baz"); |
||||
var method = baz.GetMethod ("PrintAnswer"); |
||||
|
||||
var box = method.Body.Instructions.Where (i => i.OpCode == OpCodes.Box).First (); |
||||
var int32 = (TypeReference) box.Operand; |
||||
|
||||
Assert.IsTrue (int32.IsValueType); |
||||
} |
||||
|
||||
[TestModule ("gifaceref.exe")] |
||||
public void GenericInterfaceReference (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("Program"); |
||||
var iface = type.Interfaces [0]; |
||||
|
||||
var instance = (GenericInstanceType) iface; |
||||
var owner = instance.ElementType; |
||||
|
||||
Assert.AreEqual (1, instance.GenericArguments.Count); |
||||
Assert.AreEqual (1, owner.GenericParameters.Count); |
||||
} |
||||
|
||||
[TestModule ("cscgpbug.dll", Verify = false)] |
||||
public void UnboundGenericParameter (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("ListViewModel"); |
||||
var method = type.GetMethod ("<>n__FabricatedMethod1"); |
||||
|
||||
var parameter = method.ReturnType as GenericParameter; |
||||
|
||||
Assert.IsNotNull (parameter); |
||||
Assert.AreEqual (0, parameter.Position); |
||||
Assert.IsNull (parameter.Owner); |
||||
} |
||||
|
||||
[TestCSharp ("Generics.cs")] |
||||
public void GenericMultidimensionalArray (ModuleDefinition module) |
||||
{ |
||||
var type = module.GetType ("LaMatrix"); |
||||
var method = type.GetMethod ("At"); |
||||
|
||||
var call = method.Body.Instructions.Where (i => i.Operand is MethodReference).First (); |
||||
var get = (MethodReference) call.Operand; |
||||
|
||||
Assert.IsNotNull (get); |
||||
Assert.AreEqual (0, get.GenericParameters.Count); |
||||
Assert.AreEqual (MethodCallingConvention.Default, get.CallingConvention); |
||||
Assert.AreEqual (method.GenericParameters [0], get.ReturnType); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace Mono.Cecil.Tests { |
||||
|
||||
[TestFixture] |
||||
public class VariableTests : BaseTestFixture { |
||||
|
||||
[Test] |
||||
public void AddVariableIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var x = new VariableDefinition ("x", object_ref); |
||||
var y = new VariableDefinition ("y", object_ref); |
||||
|
||||
body.Variables.Add (x); |
||||
body.Variables.Add (y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveAtVariableIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var x = new VariableDefinition ("x", object_ref); |
||||
var y = new VariableDefinition ("y", object_ref); |
||||
var z = new VariableDefinition ("z", object_ref); |
||||
|
||||
body.Variables.Add (x); |
||||
body.Variables.Add (y); |
||||
body.Variables.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
|
||||
body.Variables.RemoveAt (1); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveVariableIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var x = new VariableDefinition ("x", object_ref); |
||||
var y = new VariableDefinition ("y", object_ref); |
||||
var z = new VariableDefinition ("z", object_ref); |
||||
|
||||
body.Variables.Add (x); |
||||
body.Variables.Add (y); |
||||
body.Variables.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
|
||||
body.Variables.Remove (y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
} |
||||
|
||||
[Test] |
||||
public void InsertVariableIndex () |
||||
{ |
||||
var object_ref = new TypeReference ("System", "Object", null, null, false); |
||||
var method = new MethodDefinition ("foo", MethodAttributes.Static, object_ref); |
||||
var body = new MethodBody (method); |
||||
|
||||
var x = new VariableDefinition ("x", object_ref); |
||||
var y = new VariableDefinition ("y", object_ref); |
||||
var z = new VariableDefinition ("z", object_ref); |
||||
|
||||
body.Variables.Add (x); |
||||
body.Variables.Add (z); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (-1, y.Index); |
||||
Assert.AreEqual (1, z.Index); |
||||
|
||||
body.Variables.Insert (1, y); |
||||
|
||||
Assert.AreEqual (0, x.Index); |
||||
Assert.AreEqual (1, y.Index); |
||||
Assert.AreEqual (2, z.Index); |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Cecil ftw! |
||||
Binary file not shown.
@ -0,0 +1,152 @@
@@ -0,0 +1,152 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
[assembly: Foo ("bingo")] |
||||
|
||||
[assembly: TypeForwardedTo (typeof (System.Diagnostics.DebuggableAttribute))] |
||||
|
||||
enum Bingo : short { |
||||
Fuel = 2, |
||||
Binga = 4, |
||||
} |
||||
|
||||
/* |
||||
in System.Security.AccessControl |
||||
|
||||
[Flags] |
||||
public enum AceFlags : byte { |
||||
None = 0, |
||||
ObjectInherit = 0x01, |
||||
ContainerInherit = 0x02, |
||||
NoPropagateInherit = 0x04, |
||||
InheritOnly = 0x08, |
||||
InheritanceFlags = ObjectInherit | ContainerInherit | NoPropagateInherit | InheritOnly, |
||||
Inherited = 0x10, |
||||
SuccessfulAccess = 0x40, |
||||
FailedAccess = 0x80, |
||||
AuditFlags = SuccessfulAccess | FailedAccess, |
||||
} |
||||
*/ |
||||
|
||||
class FooAttribute : Attribute { |
||||
|
||||
internal class Token { |
||||
} |
||||
|
||||
public FooAttribute () |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (string str) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (sbyte a, byte b, bool c, bool d, ushort e, short f, char g) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (int a, uint b, float c, long d, ulong e, double f) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (char [] chars) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (object a, object b) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (Bingo bingo) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (System.Security.AccessControl.AceFlags flags) |
||||
{ |
||||
} |
||||
|
||||
public FooAttribute (Type type) |
||||
{ |
||||
} |
||||
|
||||
public int Bang { get { return 0; } set {} } |
||||
public string Fiou { get { return "fiou"; } set {} } |
||||
|
||||
public object Pan; |
||||
public string [] PanPan; |
||||
|
||||
public Type Chose; |
||||
} |
||||
|
||||
[Foo ("bar")] |
||||
class Hamster { |
||||
} |
||||
|
||||
[Foo ((string) null)] |
||||
class Dentist { |
||||
} |
||||
|
||||
[Foo (-12, 242, true, false, 4242, -1983, 'c')] |
||||
class Steven { |
||||
} |
||||
|
||||
[Foo (-100000, 200000, 12.12f, long.MaxValue, ulong.MaxValue, 64.646464)] |
||||
class Seagull { |
||||
} |
||||
|
||||
[Foo (new char [] { 'c', 'e', 'c', 'i', 'l' })] |
||||
class Rifle { |
||||
} |
||||
|
||||
[Foo ("2", 2)] |
||||
class Worm { |
||||
} |
||||
|
||||
[Foo (new object [] { "2", 2, 'c' }, new object [] { new object [] { 1, 2, 3}, null })] |
||||
class Sheep { |
||||
} |
||||
|
||||
[Foo (Bang = 42, PanPan = new string [] { "yo", "yo" }, Pan = new object [] { 1, "2", '3' }, Fiou = null)] |
||||
class Angola { |
||||
} |
||||
|
||||
[Foo (Pan = "fiouuu")] |
||||
class BoxedStringField { |
||||
} |
||||
|
||||
[Foo (Bingo.Fuel)] |
||||
class Zero { |
||||
} |
||||
|
||||
[Foo (System.Security.AccessControl.AceFlags.NoPropagateInherit)] |
||||
class Ace { |
||||
} |
||||
|
||||
[Foo (new object [] { Bingo.Fuel, Bingo.Binga }, null, Pan = System.Security.AccessControl.AceFlags.NoPropagateInherit)] |
||||
class Bzzz { |
||||
} |
||||
|
||||
[Foo (typeof (Bingo))] |
||||
class Typed { |
||||
} |
||||
|
||||
[Foo (typeof (FooAttribute.Token))] |
||||
class NestedTyped { |
||||
} |
||||
|
||||
[Foo (Chose = typeof (Typed))] |
||||
class Truc { |
||||
} |
||||
|
||||
[Foo (Chose = (Type) null)] |
||||
class Machin { |
||||
} |
||||
|
||||
[Foo (typeof (Dictionary<,>))] |
||||
class OpenGeneric<X, Y> { |
||||
} |
||||
|
||||
[Foo (typeof (Dictionary<string, OpenGeneric<Machin, int>[,]>))] |
||||
class ClosedGeneric { |
||||
} |
||||
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
using System; |
||||
|
||||
delegate void Pan (object sender, EventArgs args); |
||||
|
||||
abstract class Foo { |
||||
|
||||
public abstract event Pan Bar; |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
class Foo { |
||||
Bar bar; |
||||
} |
||||
|
||||
class Bar { |
||||
volatile int oiseau; |
||||
} |
||||
|
||||
class Baz { |
||||
bool @bool; |
||||
char @char; |
||||
sbyte @sbyte; |
||||
byte @byte; |
||||
short int16; |
||||
ushort uint16; |
||||
int int32; |
||||
uint uint32; |
||||
long int64; |
||||
ulong uint64; |
||||
float single; |
||||
double @double; |
||||
string @string; |
||||
object @object; |
||||
} |
||||
|
||||
enum Pim { |
||||
Pam = 1, |
||||
Poum = 2, |
||||
} |
||||
|
||||
class PanPan { |
||||
|
||||
public const PanPan Peter = null; |
||||
public const string QQ = "qq"; |
||||
public const string nil = null; |
||||
public const object obj = null; |
||||
public const int [] ints = null; |
||||
} |
||||
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
class Foo<TBar, TBaz> {} |
||||
|
||||
abstract class Bar<T> { |
||||
|
||||
T bang; |
||||
|
||||
public abstract Bar<T> Self (); |
||||
|
||||
public abstract Bar<string> SelfString (); |
||||
} |
||||
|
||||
abstract class Baz { |
||||
|
||||
public abstract TBang Gazonk<TBang> (object o); |
||||
|
||||
public abstract Bar<TBingo> Gazoo<TBingo> (); |
||||
} |
||||
|
||||
class Zap {} |
||||
interface IZoom {} |
||||
|
||||
class Bongo<T> where T : Zap, IZoom { |
||||
|
||||
enum Dang { |
||||
Ding = 2, |
||||
Dong = 12, |
||||
} |
||||
} |
||||
|
||||
class Parent<T> {} |
||||
class Child<T> : Parent<T> { |
||||
public T [] array; |
||||
} |
||||
class TamChild : Child<Tamtam> {} |
||||
class RecChild : Child<RecChild> {} |
||||
|
||||
class Tamtam { |
||||
|
||||
static void Foo<TFoo> (TFoo tf) |
||||
{ |
||||
} |
||||
|
||||
static void Bar () |
||||
{ |
||||
Foo (2); |
||||
} |
||||
|
||||
static List<TBeta> Beta<TBeta> () |
||||
{ |
||||
return new List<TBeta> (); |
||||
} |
||||
|
||||
static List<TCharlie> Charlie<TCharlie> () |
||||
{ |
||||
return new List<TCharlie> (); |
||||
} |
||||
} |
||||
|
||||
class It { |
||||
|
||||
public IEnumerable<Foo<string, string>> Pwow () |
||||
{ |
||||
yield return new Foo<string, string> (); |
||||
yield return new Foo<string, string> (); |
||||
yield return new Foo<string, string> (); |
||||
} |
||||
|
||||
public void ReadPwow () |
||||
{ |
||||
foreach (Foo<string, string> foo in Pwow ()) |
||||
Tac (foo); |
||||
} |
||||
|
||||
public void Tac<T> (T t) |
||||
{ |
||||
} |
||||
} |
||||
|
||||
class Duel<T1, T2, T3> where T2 : T1 where T3 : T2 {} |
||||
|
||||
class ChildReader { |
||||
|
||||
public int Read (TamChild t) |
||||
{ |
||||
return t.array.Length; |
||||
} |
||||
} |
||||
|
||||
struct Nilible<T> where T : struct { |
||||
public T t; |
||||
} |
||||
|
||||
class Null { |
||||
|
||||
public static int Compare<T> (Nilible<T> x, Nilible<T> y) where T : struct |
||||
{ |
||||
return Comparer<T>.Default.Compare (x.t, y.t); |
||||
} |
||||
} |
||||
|
||||
public class DoubleFuncClass { |
||||
public void Test () { Test<int> (); Test<int, int> (); } |
||||
public void Test<T> () { Test<T, int> (); Test<T, T> (); } |
||||
public void Test<T, T1> () { Test<T1> (); Test<T1, T> (); } |
||||
} |
||||
|
||||
public class DoubleFuncClass<X> { |
||||
public void Test () { Test<int> (); Test<int, int> (); } |
||||
public void Test<T> () { Test<X, int> (); Test<T, X> (); } |
||||
public void Test<T, T1> () { Test<T1> (); Test<T1, T> (); } |
||||
} |
||||
|
||||
public class LaMatrix { |
||||
public static T At<T> (T[,] m, int i, int j) |
||||
{ |
||||
return m [i, j]; |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
using System; |
||||
|
||||
interface IFoo {} |
||||
interface IBar : IFoo {} |
||||
|
||||
abstract class Bar : IBar {} |
||||
|
||||
interface IBingo { |
||||
void Foo (); |
||||
void Bar (); |
||||
} |
||||
|
||||
class Bingo : IBingo { |
||||
|
||||
void IBingo.Foo () |
||||
{ |
||||
} |
||||
|
||||
void IBingo.Bar () |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
[StructLayout (LayoutKind.Explicit, Size = 16)] |
||||
public struct Foo { |
||||
[FieldOffset (0)] public ushort Bar; |
||||
[FieldOffset (2)] public ushort Baz; |
||||
[FieldOffset (4)] public uint Gazonk; |
||||
} |
||||
|
||||
class Babar { |
||||
} |
||||
|
||||
class Locke { |
||||
public int [] integers = new int [] { 1, 2, 3, 4 }; |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
abstract class Foo { |
||||
public abstract void Bar (int a); |
||||
} |
||||
|
||||
class Bar { |
||||
|
||||
[DllImport ("foo.dll")] |
||||
public extern static void Pan ([MarshalAs (UnmanagedType.I4)] int i); |
||||
} |
||||
|
||||
public class Baz { |
||||
|
||||
public void PrintAnswer () |
||||
{ |
||||
Console.WriteLine ("answer: {0}", 42); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
class Foo { |
||||
class Bar { |
||||
class Baz { |
||||
} |
||||
} |
||||
} |
||||
|
||||
class Bingo { |
||||
public class Fuel { |
||||
} |
||||
|
||||
public static Fuel GetFuel () |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
using System; |
||||
|
||||
abstract class Foo { |
||||
|
||||
public abstract int Bar { get; } |
||||
public abstract string Baz { get; set; } |
||||
public abstract string Gazonk { set; } |
||||
} |
||||
|
||||
abstract class Bar { |
||||
|
||||
public abstract Foo this [int a, string s] { set; } |
||||
} |
||||
|
||||
class Baz { |
||||
|
||||
public string Bingo { get; set; } |
||||
} |
||||
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89) |
||||
.ver 2:0:0:0 |
||||
} |
||||
|
||||
.assembly Hello {} |
||||
|
||||
.module Hello.dll |
||||
|
||||
.class private auto ansi Foo { |
||||
|
||||
.method public specialname rtspecialname instance void .ctor () cil managed |
||||
{ |
||||
ldarg.0 |
||||
call instance void [mscorlib]System.Object::.ctor () |
||||
ret |
||||
} |
||||
|
||||
.method public static void Bar (int32 a, int32 b) |
||||
{ |
||||
.locals init (int32 res) |
||||
ldarg.0 |
||||
ldarg.1 |
||||
mul |
||||
stloc.0 |
||||
ldloc.0 |
||||
call void Foo::Baz (int32) |
||||
ret |
||||
} |
||||
|
||||
.method public static void Baz (int32 a) |
||||
{ |
||||
ret |
||||
} |
||||
|
||||
.method public void Gazonk () |
||||
{ |
||||
ldarg 0 |
||||
pop |
||||
ret |
||||
} |
||||
|
||||
.method public static void PrintEmpty () |
||||
{ |
||||
ldsfld string [mscorlib]System.String::Empty |
||||
call void [mscorlib]System.Console::WriteLine(string) |
||||
ret |
||||
} |
||||
|
||||
.method public static bool TestFilter (bool b) cil managed |
||||
{ |
||||
.maxstack 2 |
||||
.locals init (bool flag) |
||||
beginTry: |
||||
newobj instance void [mscorlib]System.Exception::.ctor () |
||||
throw |
||||
leave endCatch |
||||
startFilter: |
||||
pop |
||||
ldarg.0 |
||||
endfilter |
||||
startCatch: |
||||
ldc.i4.1 |
||||
stloc.0 |
||||
leave return |
||||
leave endCatch |
||||
endCatch: |
||||
L_001b: ldc.i4.0 |
||||
L_001c: stloc.0 |
||||
return: |
||||
L_001d: ldloc.0 |
||||
L_001e: ret |
||||
.try beginTry to startFilter filter startFilter handler startCatch to endCatch |
||||
} |
||||
|
||||
.method public static !!T GetState<T>(string var, [opt] !!T defaultValue) cil managed |
||||
{ |
||||
.param [2] = nullref |
||||
|
||||
ldarg.1 |
||||
ret |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
|
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) |
||||
.ver 2:0:0:0 |
||||
} |
||||
|
||||
.assembly MethodSpecs |
||||
{ |
||||
} |
||||
|
||||
.module MethodSpecs.dll |
||||
|
||||
.class private auto ansi beforefieldinit Tamtam |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method private hidebysig static void Foo<TFoo>(!!TFoo tf) cil managed |
||||
{ |
||||
// Code size 1 (0x1) |
||||
.maxstack 8 |
||||
IL_0000: ret |
||||
} // end of method Tamtam::Foo |
||||
|
||||
.method private hidebysig static void Bar() cil managed |
||||
{ |
||||
// Code size 7 (0x7) |
||||
.maxstack 8 |
||||
IL_0000: ldc.i4.2 |
||||
IL_0001: call void Tamtam::Foo<int32>(!!0) |
||||
IL_0006: ret |
||||
} // end of method Tamtam::Bar |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 7 (0x7) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: ret |
||||
} // end of method Tamtam::.ctor |
||||
|
||||
} // end of class Tamtam |
||||
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89) |
||||
.ver 2:0:0:0 |
||||
} |
||||
|
||||
.assembly Others {} |
||||
|
||||
.module Others.dll |
||||
|
||||
.class private auto ansi Others { |
||||
|
||||
.field private string _context |
||||
|
||||
.method public specialname instance string get_Context () cil managed |
||||
{ |
||||
ldarg.0 |
||||
ldfld string Others::_context |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void set_Context (string val) cil managed |
||||
{ |
||||
ldarg.0 |
||||
ldarg.1 |
||||
stfld string Others::_context |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void let_Context (string val) cil managed |
||||
{ |
||||
ldarg.0 |
||||
ldarg.1 |
||||
stfld string Others::_context |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void bet_Context (string val) cil managed |
||||
{ |
||||
ldarg.0 |
||||
ldarg.1 |
||||
stfld string Others::_context |
||||
ret |
||||
} |
||||
|
||||
.property instance string Context () { |
||||
.get instance string Others::get_Context () |
||||
.set instance void Others::set_Context (string val) |
||||
.other instance void Others::let_Context (string val) |
||||
.other instance void Others::bet_Context (string val) |
||||
} |
||||
|
||||
.field private class [mscorlib]System.EventHandler _handler |
||||
|
||||
.method public specialname instance void remove_Handler (class [mscorlib]System.EventHandler) cil managed |
||||
{ |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void add_Handler (class [mscorlib]System.EventHandler) cil managed |
||||
{ |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void dang_Handler (class [mscorlib]System.EventHandler) cil managed |
||||
{ |
||||
ret |
||||
} |
||||
|
||||
.method public specialname instance void fang_Handler (class [mscorlib]System.EventHandler) cil managed |
||||
{ |
||||
ret |
||||
} |
||||
|
||||
.event [mscorlib]System.EventHandler Handler { |
||||
.removeon instance void Others::remove_Handler (class [mscorlib]System.EventHandler) |
||||
.addon instance void Others::add_Handler (class [mscorlib]System.EventHandler) |
||||
.other instance void Others::dang_Handler (class [mscorlib]System.EventHandler) |
||||
.other instance void Others::fang_Handler (class [mscorlib]System.EventHandler) |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89) |
||||
.ver 2:0:0:0 |
||||
} |
||||
|
||||
.assembly Types {} |
||||
|
||||
.module Types.dll |
||||
|
||||
.class private auto ansi Types { |
||||
|
||||
.field public int32[,] rank_two |
||||
.field public int32[0...,0...] rank_two_low_bound_zero |
||||
.field public int32[-1...4] rank_one_low_bound_m1 |
||||
|
||||
.method public specialname rtspecialname instance void .ctor () cil managed |
||||
{ |
||||
ldarg.0 |
||||
call instance void [mscorlib]System.Object::.ctor () |
||||
ret |
||||
} |
||||
} |
||||
|
||||
.class interface private abstract auto ansi IFoo |
||||
{ |
||||
} |
||||
|
||||
.class interface private abstract auto ansi IBar |
||||
implements IFoo |
||||
{ |
||||
} |
||||
|
||||
.class interface private abstract IBaz |
||||
implements IBar, IFoo |
||||
{ |
||||
} |
||||
|
||||
.class private Fields { |
||||
|
||||
.field private static literal int32 int32_int16 = int16(0x0001) |
||||
.field private static literal int16 int16_int32 = int32(0x00000001) |
||||
.field private static literal char char_int16 = int16(0x0001) |
||||
.field private static literal int16 int16_char = char(0x0073) |
||||
.field private static literal int32 int32_nullref = nullref |
||||
} |
||||
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
Copyright © 2002-2007 Charlie Poole |
||||
Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov |
||||
Copyright © 2000-2002 Philip A. Craig |
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. |
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: |
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment (see the following) in the product documentation is required. |
||||
|
||||
Portions Copyright © 2002-2007 Charlie Poole or Copyright © 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov or Copyright © 2000-2002 Philip A. Craig |
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
||||
|
||||
3. This notice may not be removed or altered from any source distribution. |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
See http://www.mono-project.com/Cecil |
||||
Cecil 0.9: http://evain.net/blog/articles/2010/04/12/mono-cecil-0-9-cecil-light |
||||
|
||||
* License |
||||
|
||||
Copyright (c) 2008 - 2011 Jb Evain |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the |
||||
"Software"), to deal in the Software without restriction, including |
||||
without limitation the rights to use, copy, modify, merge, publish, |
||||
distribute, sublicense, and/or sell copies of the Software, and to |
||||
permit persons to whom the Software is furnished to do so, subject to |
||||
the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be |
||||
included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
Loading…
Reference in new issue