mirror of https://github.com/icsharpcode/ILSpy.git
21 changed files with 493 additions and 39 deletions
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
|
||||
namespace ILSpy.BamlDecompiler |
||||
{ |
||||
public static class Extensions |
||||
{ |
||||
public static string TrimEnd(this string target, Func<char, bool> predicate) |
||||
{ |
||||
if (target == null) |
||||
throw new ArgumentNullException("target"); |
||||
|
||||
while (predicate(target.LastOrDefault())) |
||||
target = target.Remove(target.Length - 1); |
||||
|
||||
return target; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
// This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
namespace Ricciolo.StylesExplorer.MarkupReflection |
||||
{ |
||||
class XmlBamlSimpleProperty : XmlBamlNode |
||||
{ |
||||
public string NamespaceName { get; private set; } |
||||
public string LocalName { get; private set; } |
||||
public string Value { get; private set; } |
||||
|
||||
public XmlBamlSimpleProperty(string namespaceName, string localName, string value) |
||||
{ |
||||
if (string.IsNullOrWhiteSpace(namespaceName)) |
||||
throw new ArgumentException("namespaceName"); |
||||
if (string.IsNullOrWhiteSpace(localName)) |
||||
throw new ArgumentException("localName"); |
||||
if (value == null) |
||||
throw new ArgumentNullException("value"); |
||||
this.NamespaceName = namespaceName; |
||||
this.LocalName = localName; |
||||
this.Value = value; |
||||
} |
||||
|
||||
public override XmlNodeType NodeType { |
||||
get { return XmlNodeType.Attribute; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
<Window x:Class="ILSpy.BamlDecompiler.Tests.Cases.Simple" Title="ILSpy.BamlDecompiler.Tests.Cases" Height="300" Width="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<Grid /> |
||||
</Window> |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ILSpy.BamlDecompiler.Tests.Cases |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for Simple.xaml
|
||||
/// </summary>
|
||||
public partial class Simple : Window |
||||
{ |
||||
public Simple() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></ResourceDictionary> |
@ -0,0 +1,112 @@
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{1169E6D1-1899-43D4-A500-07CE4235B388}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ILSpy.BamlDecompiler.Tests</RootNamespace> |
||||
<AssemblyName>ILSpy.BamlDecompiler.Tests</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>..\bin\Debug\</OutputPath> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<Optimize>False</Optimize> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>..\bin\Release\</OutputPath> |
||||
<DebugSymbols>false</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="DiffLib"> |
||||
<HintPath>..\..\packages\DiffLib.1.0.0.55\lib\net35-Client\DiffLib.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\ICSharpCode.Decompiler\Tests\nunit.framework.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="PresentationCore" /> |
||||
<Reference Include="PresentationCore"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="PresentationFramework" /> |
||||
<Reference Include="PresentationFramework"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xaml"> |
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="WindowsBase" /> |
||||
<Reference Include="WindowsBase"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Cases\Simple.xaml.cs"> |
||||
<DependentUpon>Simple.xaml</DependentUpon> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="TestRunner.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\ICSharpCode.Decompiler\Tests\ICSharpCode.Decompiler.Tests.csproj"> |
||||
<Project>{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}</Project> |
||||
<Name>ICSharpCode.Decompiler.Tests</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\ILSpy\ILSpy.csproj"> |
||||
<Project>{1E85EFF9-E370-4683-83E4-8A3D063FF791}</Project> |
||||
<Name>ILSpy</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\Mono.Cecil\Mono.Cecil.csproj"> |
||||
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project> |
||||
<Name>Mono.Cecil</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\SharpTreeView\ICSharpCode.TreeView.csproj"> |
||||
<Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project> |
||||
<Name>ICSharpCode.TreeView</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\ILSpy.BamlDecompiler.csproj"> |
||||
<Project>{A6BAD2BA-76BA-461C-8B6D-418607591247}</Project> |
||||
<Name>ILSpy.BamlDecompiler</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="Cases" /> |
||||
<Folder Include="Properties" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Page Include="Cases\Simple.xaml"> |
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||
</Page> |
||||
<Page Include="Cases\SimpleDictionary.xaml" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ILSpy.BamlDecompiler.Tests")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ILSpy.BamlDecompiler.Tests")] |
||||
[assembly: AssemblyCopyright("Copyright 2011")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Resources; |
||||
using System.Xml.Linq; |
||||
using ICSharpCode.Decompiler.Tests.Helpers; |
||||
using ICSharpCode.ILSpy; |
||||
using Mono.Cecil; |
||||
using NUnit.Framework; |
||||
using Ricciolo.StylesExplorer.MarkupReflection; |
||||
|
||||
namespace ILSpy.BamlDecompiler.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class TestRunner |
||||
{ |
||||
[Test] |
||||
public void Simple() |
||||
{ |
||||
RunTest("cases/simple"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleDictionary() |
||||
{ |
||||
RunTest("cases/simpledictionary"); |
||||
} |
||||
|
||||
void RunTest(string name) |
||||
{ |
||||
string asmPath = typeof(TestRunner).Assembly.Location; |
||||
var assembly = AssemblyDefinition.ReadAssembly(asmPath); |
||||
Resource res = assembly.MainModule.Resources.First(); |
||||
Stream bamlStream = LoadBaml(res, name + ".baml"); |
||||
Assert.IsNotNull(bamlStream); |
||||
XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream); |
||||
string path = Path.Combine("..\\..\\Tests", name + ".xaml"); |
||||
|
||||
CodeAssert.AreEqual(document.ToString(), File.ReadAllText(path)); |
||||
} |
||||
|
||||
Stream LoadBaml(Resource res, string name) |
||||
{ |
||||
EmbeddedResource er = res as EmbeddedResource; |
||||
if (er != null) { |
||||
Stream s = er.GetResourceStream(); |
||||
s.Position = 0; |
||||
ResourceReader reader; |
||||
try { |
||||
reader = new ResourceReader(s); |
||||
} |
||||
catch (ArgumentException) { |
||||
return null; |
||||
} |
||||
foreach (DictionaryEntry entry in reader.Cast<DictionaryEntry>().OrderBy(e => e.Key.ToString())) { |
||||
if (entry.Key.ToString() == name) { |
||||
if (entry.Value is Stream) |
||||
return (Stream)entry.Value; |
||||
if (entry.Value is byte[]) |
||||
return new MemoryStream((byte[])entry.Value); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue