Skip to content

Commit

Permalink
Finish updating ilspy plugin and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Feb 12, 2020
1 parent 19b186b commit 2d47443
Show file tree
Hide file tree
Showing 123 changed files with 474 additions and 184 deletions.
Binary file modified Resources/Dependencies/ILSpy/ICSharpCode.AvalonEdit.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/ICSharpCode.Decompiler.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/ICSharpCode.TreeView.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/ILSpy.BamlDecompiler.Plugin.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/ILSpy.exe
Binary file not shown.
337 changes: 318 additions & 19 deletions Resources/Dependencies/ILSpy/ILSpy.exe.config

Large diffs are not rendered by default.

Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/Mono.Cecil.Mdb.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/Mono.Cecil.Pdb.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/Mono.Cecil.Rocks.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/Mono.Cecil.dll
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/OSVersionHelper.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/System.Collections.Immutable.dll
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 added Resources/Dependencies/ILSpy/System.Console.dll
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 added Resources/Dependencies/ILSpy/System.IO.Pipes.dll
Binary file not shown.
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/System.IO.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/System.Linq.dll
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/System.Net.Http.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/System.Net.Ping.dll
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 added Resources/Dependencies/ILSpy/System.Runtime.dll
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 added Resources/Dependencies/ILSpy/System.Threading.dll
Binary file not shown.
Binary file modified Resources/Dependencies/ILSpy/System.ValueTuple.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/System.Xml.XPath.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Resources/Dependencies/ILSpy/netstandard.dll
Binary file not shown.
Binary file not shown.
10 changes: 8 additions & 2 deletions Tools/ILSpyPlugAddIn/ILSpyPlugAddIn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpyPlugAddIn", "ILSpyPlugAddIn\ILSpyPlugAddIn.csproj", "{08FE791B-5864-4E6F-AF7B-A02742C9C764}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpyPlugAddin", "ILSpyPlugAddin\ILSpyPlugAddin.csproj", "{08FE791B-5864-4E6F-AF7B-A02742C9C764}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyPlugAddin.Tests", "ILSpyPlugAddin.Tests\ILSpyPlugAddin.Tests\ILSpyPlugAddin.Tests.csproj", "{573518BB-28C4-47DC-81A1-1C1FECDD87D3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpyPlugAddin.Tests", "ILSpyPlugAddin.Tests\ILSpyPlugAddin.Tests.csproj", "{573518BB-28C4-47DC-81A1-1C1FECDD87D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly", "TestAssembly\TestAssembly.csproj", "{C13647E4-4A55-4962-9834-D2A26E54B985}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,10 @@ Global
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{573518BB-28C4-47DC-81A1-1C1FECDD87D3}.Release|Any CPU.Build.0 = Release|Any CPU
{C13647E4-4A55-4962-9834-D2A26E54B985}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C13647E4-4A55-4962-9834-D2A26E54B985}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C13647E4-4A55-4962-9834-D2A26E54B985}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C13647E4-4A55-4962-9834-D2A26E54B985}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.Windows;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;

namespace Cosmos.ILSpyPlugs.Plugin
{
Expand All @@ -20,7 +15,7 @@ public override bool IsVisible(TextViewContext context)
foreach (var node in context.SelectedTreeNodes)
{
var xCurrentField = node as FieldTreeNode;
if ((xCurrentField != null) && !xCurrentField.FieldDefinition.HasConstant)
if ((xCurrentField != null) && !xCurrentField.FieldDefinition.IsConst)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.Windows;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;

namespace Cosmos.ILSpyPlugs.Plugin
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.Windows;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;

namespace Cosmos.ILSpyPlugs.Plugin
{
Expand Down Expand Up @@ -42,7 +37,7 @@ public override void Execute(TextViewContext context)
var xCurrentProperty = node as PropertyTreeNode;
if (node != null)
{
xString.Append(GenerateProperty(xCurrentProperty.PropertyDefinition));
xString.Append(Utilities.GeneratePropertyPlugEntry(xCurrentProperty.PropertyDefinition));
xString.AppendLine();
}
}
Expand All @@ -51,21 +46,5 @@ public override void Execute(TextViewContext context)

MessageBox.Show("Done", "Cosmos Plug tool");
}

public string GenerateProperty(PropertyDefinition property)
{
StringBuilder xString = new StringBuilder();
if (property.GetMethod != null)
{
xString.AppendLine(Utilities.GenerateMethodPlugEntry(property.GetMethod));
xString.AppendLine();
}
if (property.SetMethod != null)
{
xString.AppendLine(Utilities.GenerateMethodPlugEntry(property.SetMethod));
xString.AppendLine();
}
return xString.ToString();
}
}
}
7 changes: 1 addition & 6 deletions Tools/ILSpyPlugAddIn/ILSpyPlugAddin/GenerateTypePlugEntry.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using System.Windows;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil;

namespace Cosmos.ILSpyPlugs.Plugin
{
Expand Down
4 changes: 2 additions & 2 deletions Tools/ILSpyPlugAddIn/ILSpyPlugAddin/ILSpyPlugAddIn.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFramework>net462</TargetFramework>
<RootNamespace>Cosmos.ILSpyPlugs.Plugin</RootNamespace>
<AssemblyName>Cosmos.ILSpyPlugs.Plugin</AssemblyName>
<IncludeWpfReferences>True</IncludeWpfReferences>
</PropertyGroup>

<ItemGroup>
<ILSpyReference Include="ICSharpCode.TreeView.dll" />
<ILSpyReference Include="ICSharpCode.Decompiler.dll" />
<ILSpyReference Include="ILSpy.exe" />
<ILSpyReference Include="Mono.Cecil.dll" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"profiles": {
"ILSpyPlugAddIn": {
"ILSpyPlugAddin": {
"commandName": "Executable",
"executablePath": "./ILSpy.exe"
}
Expand Down
66 changes: 41 additions & 25 deletions Tools/ILSpyPlugAddIn/ILSpyPlugAddin/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy;
using Mono.Cecil;

namespace Cosmos.ILSpyPlugs.Plugin
{
public static class Utilities
{
public static string GenerateTypePlugEntry(TypeDefinition type)
public static string GenerateTypePlugEntry(ITypeDefinition type)
{
var xString = new StringBuilder();
xString.AppendFormat(
type.IsPublic
var xSB = new StringBuilder();
xSB.AppendFormat(
type.Accessibility == Accessibility.Public
? "[Plug(Target = typeof(global::{0}))]"
: "[Plug(TargetName = \"{0}, {1}\")]", Utilities.GetCSharpTypeName(type), type.Module.Assembly.Name);
xString.AppendLine();
xString.AppendFormat("public static class {0}Impl", type.Name);
xString.AppendLine();
xString.AppendLine("{");
xString.AppendLine("}");
return xString.ToString();
: "[Plug(TargetName = \"{0}, {1}\")]", Utilities.GetCSharpTypeName(type), type.ParentModule.AssemblyName);
xSB.AppendLine();
xSB.AppendFormat("public static class {0}Impl", type.Name);
xSB.AppendLine();
xSB.AppendLine("{");
xSB.AppendLine("}");
return xSB.ToString();
}

public static string GenerateMethodPlugEntry(MethodDefinition method)
public static string GenerateMethodPlugEntry(IMethod method)
{
var xSB = new StringBuilder();

Expand All @@ -34,11 +34,11 @@ public static string GenerateMethodPlugEntry(MethodDefinition method)

if (!method.IsStatic)
{
if (method.DeclaringType.IsValueType)
if (method.DeclaringType.IsReferenceType ?? false)
{
xSB.Append("ref ");
}
if (method.DeclaringType.IsPublic)
if (method.DeclaringType.GetDefinition().Accessibility == Accessibility.Public)
{
xSB.Append(Utilities.GetCSharpTypeName(method.DeclaringType));
}
Expand All @@ -58,11 +58,11 @@ public static string GenerateMethodPlugEntry(MethodDefinition method)
xSB.Append(", ");
}
xAddComma = true;
var xParameterTypeDef = xParameter.ParameterType as TypeDefinition;
var xParameterTypeDef = xParameter.Type.GetDefinition();
if (xParameterTypeDef != null
&& xParameterTypeDef.IsPublic)
&& xParameterTypeDef.Accessibility == Accessibility.Public)
{
xSB.Append(Utilities.GetCSharpTypeName(xParameter.ParameterType));
xSB.Append(Utilities.GetCSharpTypeName(xParameter.Type));
}
else
{
Expand All @@ -78,21 +78,37 @@ public static string GenerateMethodPlugEntry(MethodDefinition method)
return xSB.ToString();
}

public static string GenerateFieldAccessPlugEntry(FieldDefinition field)
public static string GenerateFieldAccessPlugEntry(IField field)
{
StringBuilder xString = new StringBuilder();
xString.Append($"[FieldAccess(Name = \"{field.FieldType.FullName} {field.DeclaringType.FullName}.{field.Name}\")] ref {Utilities.GetCSharpTypeName(field.FieldType)} field{field.Name}");
return xString.ToString();
var xSB = new StringBuilder();
xSB.Append($"[FieldAccess(Name = \"{field.Type.FullName} {field.DeclaringType.FullName}.{field.Name}\")] ref {Utilities.GetCSharpTypeName(field.Type)} field{field.Name}");
return xSB.ToString();
}

public static string GeneratePropertyPlugEntry(IProperty property)
{
var xSB = new StringBuilder();
if (property.Getter != null)
{
xSB.AppendLine(GenerateMethodPlugEntry(property.Getter));
xSB.AppendLine();
}
if (property.Setter != null)
{
xSB.AppendLine(GenerateMethodPlugEntry(property.Setter));
xSB.AppendLine();
}
return xSB.ToString();
}

public static string GetCSharpTypeName(TypeReference reference)
private static string GetCSharpTypeName(IType type)
{
var xCSharp = Languages.GetLanguage("C#");

return xCSharp.TypeToString(reference, true);
return xCSharp.TypeToString(type, true);
}

public static string GetMethodName(MethodDefinition method)
private static string GetMethodName(IMethod method)
{
if (method.IsConstructor)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFramework>net462</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -13,13 +13,14 @@
</ItemGroup>

<ItemGroup>
<ILSpyReference Include="ICSharpCode.TreeView.dll" />
<ILSpyReference Include="ILSpy.exe" />
<ILSpyReference Include="Mono.Cecil.dll" />
<ProjectReference Include="..\ILSpyPlugAddin\ILSpyPlugAddin.csproj" />
<ProjectReference Include="..\TestAssembly\TestAssembly.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\ILSpyPlugAddIn\ILSpyPlugAddIn.csproj" />
<ILSpyReference Include="ICSharpCode.TreeView.dll" />
<ILSpyReference Include="ICSharpCode.Decompiler.dll" />
<ILSpyReference Include="ILSpy.exe" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 2d47443

Please sign in to comment.