Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy

pull/205/head
Pent Ploompuu 15 years ago
parent
commit
738e3fb776
  1. 5
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 17
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  3. 6
      ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs
  4. 9
      ICSharpCode.Decompiler/Tests/PInvoke.cs
  5. 34
      ILSpy/AssemblyListManager.cs
  6. 34
      ILSpy/Commands/OpenListCommand.cs
  7. 24
      ILSpy/CreateListDialog.xaml
  8. 49
      ILSpy/CreateListDialog.xaml.cs
  9. 12
      ILSpy/ILSpy.csproj
  10. 48
      ILSpy/MainWindow.xaml.cs
  11. 41
      ILSpy/OpenListDialog.xaml
  12. 184
      ILSpy/OpenListDialog.xaml.cs
  13. 18
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  14. 87
      ILSpy/XmlDoc/XmlDocKeyProvider.cs
  15. 33
      NRefactory/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs
  16. 92
      NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs
  17. 55
      NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs
  18. 6
      NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  19. 11
      NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  20. 2078
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstTransformer.cs
  21. 1156
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstVisitor.cs
  22. 1266
      NRefactory/ICSharpCode.NRefactory.VB/Visitors/NodeTrackingAstVisitor.cs
  23. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/InsertParenthesesVisitor.cs
  24. 4
      doc/Command Line.txt

5
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -1112,6 +1112,11 @@ namespace ICSharpCode.Decompiler.Ast
attributedNode.Attributes.Add(new AttributeSection(CreateNonCustomAttribute(typeof(SerializableAttribute)))); attributedNode.Attributes.Add(new AttributeSection(CreateNonCustomAttribute(typeof(SerializableAttribute))));
#endregion #endregion
#region ComImportAttribute
if (typeDefinition.IsImport)
attributedNode.Attributes.Add(new AttributeSection(CreateNonCustomAttribute(typeof(ComImportAttribute))));
#endregion
#region StructLayoutAttribute #region StructLayoutAttribute
LayoutKind layoutKind = LayoutKind.Auto; LayoutKind layoutKind = LayoutKind.Auto;
switch (typeDefinition.Attributes & TypeAttributes.LayoutMask) { switch (typeDefinition.Attributes & TypeAttributes.LayoutMask) {

17
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -977,29 +977,29 @@ namespace ICSharpCode.Decompiler.Ast
if (cecilMethodDef.IsGetter && methodArgs.Count == 0) { if (cecilMethodDef.IsGetter && methodArgs.Count == 0) {
foreach (var prop in cecilMethodDef.DeclaringType.Properties) { foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
if (prop.GetMethod == cecilMethodDef) if (prop.GetMethod == cecilMethodDef)
return target.Member(prop.Name).WithAnnotation(prop); return target.Member(prop.Name).WithAnnotation(prop).WithAnnotation(cecilMethod);
} }
} else if (cecilMethodDef.IsGetter) { // with parameters } else if (cecilMethodDef.IsGetter) { // with parameters
PropertyDefinition indexer = GetIndexer(cecilMethodDef); PropertyDefinition indexer = GetIndexer(cecilMethodDef);
if (indexer != null) if (indexer != null)
return target.Indexer(methodArgs).WithAnnotation(indexer); return target.Indexer(methodArgs).WithAnnotation(indexer).WithAnnotation(cecilMethod);
} else if (cecilMethodDef.IsSetter && methodArgs.Count == 1) { } else if (cecilMethodDef.IsSetter && methodArgs.Count == 1) {
foreach (var prop in cecilMethodDef.DeclaringType.Properties) { foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
if (prop.SetMethod == cecilMethodDef) if (prop.SetMethod == cecilMethodDef)
return new Ast.AssignmentExpression(target.Member(prop.Name).WithAnnotation(prop), methodArgs[0]); return new Ast.AssignmentExpression(target.Member(prop.Name).WithAnnotation(prop).WithAnnotation(cecilMethod), methodArgs[0]);
} }
} else if (cecilMethodDef.IsSetter && methodArgs.Count > 1) { } else if (cecilMethodDef.IsSetter && methodArgs.Count > 1) {
PropertyDefinition indexer = GetIndexer(cecilMethodDef); PropertyDefinition indexer = GetIndexer(cecilMethodDef);
if (indexer != null) if (indexer != null)
return new AssignmentExpression( return new AssignmentExpression(
target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer), target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer).WithAnnotation(cecilMethod),
methodArgs[methodArgs.Count - 1] methodArgs[methodArgs.Count - 1]
); );
} else if (cecilMethodDef.IsAddOn && methodArgs.Count == 1) { } else if (cecilMethodDef.IsAddOn && methodArgs.Count == 1) {
foreach (var ev in cecilMethodDef.DeclaringType.Events) { foreach (var ev in cecilMethodDef.DeclaringType.Events) {
if (ev.AddMethod == cecilMethodDef) { if (ev.AddMethod == cecilMethodDef) {
return new Ast.AssignmentExpression { return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev), Left = target.Member(ev.Name).WithAnnotation(ev).WithAnnotation(cecilMethod),
Operator = AssignmentOperatorType.Add, Operator = AssignmentOperatorType.Add,
Right = methodArgs[0] Right = methodArgs[0]
}; };
@ -1009,7 +1009,7 @@ namespace ICSharpCode.Decompiler.Ast
foreach (var ev in cecilMethodDef.DeclaringType.Events) { foreach (var ev in cecilMethodDef.DeclaringType.Events) {
if (ev.RemoveMethod == cecilMethodDef) { if (ev.RemoveMethod == cecilMethodDef) {
return new Ast.AssignmentExpression { return new Ast.AssignmentExpression {
Left = target.Member(ev.Name).WithAnnotation(ev), Left = target.Member(ev.Name).WithAnnotation(ev).WithAnnotation(cecilMethod),
Operator = AssignmentOperatorType.Subtract, Operator = AssignmentOperatorType.Subtract,
Right = methodArgs[0] Right = methodArgs[0]
}; };
@ -1017,7 +1017,7 @@ namespace ICSharpCode.Decompiler.Ast
} }
} else if (cecilMethodDef.Name == "Invoke" && cecilMethodDef.DeclaringType.BaseType != null && cecilMethodDef.DeclaringType.BaseType.FullName == "System.MulticastDelegate") { } else if (cecilMethodDef.Name == "Invoke" && cecilMethodDef.DeclaringType.BaseType != null && cecilMethodDef.DeclaringType.BaseType.FullName == "System.MulticastDelegate") {
AdjustArgumentsForMethodCall(cecilMethod, methodArgs); AdjustArgumentsForMethodCall(cecilMethod, methodArgs);
return target.Invoke(methodArgs); return target.Invoke(methodArgs).WithAnnotation(cecilMethod);
} }
} }
// Default invocation // Default invocation
@ -1030,7 +1030,8 @@ namespace ICSharpCode.Decompiler.Ast
// Convert 'ref' into 'out' where necessary // Convert 'ref' into 'out' where necessary
for (int i = 0; i < methodArgs.Count && i < cecilMethod.Parameters.Count; i++) { for (int i = 0; i < methodArgs.Count && i < cecilMethod.Parameters.Count; i++) {
DirectionExpression dir = methodArgs[i] as DirectionExpression; DirectionExpression dir = methodArgs[i] as DirectionExpression;
if (dir != null && cecilMethod.Parameters[i].IsOut) ParameterDefinition p = cecilMethod.Parameters[i];
if (dir != null && p.IsOut && !p.IsIn)
dir.FieldDirection = FieldDirection.Out; dir.FieldDirection = FieldDirection.Out;
} }
} }

6
ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs

@ -107,6 +107,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
AstNode fieldOrEventDecl = members.FirstOrDefault(f => f.Annotation<FieldDefinition>() == fieldDef); AstNode fieldOrEventDecl = members.FirstOrDefault(f => f.Annotation<FieldDefinition>() == fieldDef);
if (fieldOrEventDecl == null) if (fieldOrEventDecl == null)
break; break;
Expression initializer = m.Get<Expression>("initializer").Single();
// 'this'/'base' cannot be used in field initializers
if (initializer.DescendantsAndSelf.Any(n => n is ThisReferenceExpression || n is BaseReferenceExpression))
break;
allSame = true; allSame = true;
for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) { for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) {
@ -116,7 +120,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
if (allSame) { if (allSame) {
foreach (var ctor in instanceCtorsNotChainingWithThis) foreach (var ctor in instanceCtorsNotChainingWithThis)
ctor.Body.First().Remove(); ctor.Body.First().Remove();
fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = m.Get<Expression>("initializer").Single().Detach(); fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = initializer.Detach();
} }
} while (allSame); } while (allSame);
} }

9
ICSharpCode.Decompiler/Tests/PInvoke.cs

@ -84,4 +84,13 @@ public class PInvoke
public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler", MarshalCookie = "Cookie")] object o) public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler", MarshalCookie = "Cookie")] object o)
{ {
} }
[DllImport("ws2_32.dll", SetLastError = true)]
internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In] [Out] ref int argp);
public void CallMethodWithInOutParameter()
{
int num = 0;
PInvoke.ioctlsocket(IntPtr.Zero, 0, ref num);
}
} }

34
ILSpy/AssemblyListManager.cs

@ -90,5 +90,39 @@ namespace ICSharpCode.ILSpy
doc.Add(list.SaveAsXml()); doc.Add(list.SaveAsXml());
}); });
} }
public bool CreateList(AssemblyList list)
{
if (!AssemblyLists.Contains(list.ListName))
{
AssemblyLists.Add(list.ListName);
SaveList(list);
return true;
}
return false;
}
public bool DeleteList(string Name)
{
if (AssemblyLists.Contains(Name))
{
AssemblyLists.Remove(Name);
ILSpySettings.Update(
delegate(XElement root)
{
XElement doc = root.Element("AssemblyLists");
if (doc == null)
{
return;
}
XElement listElement = doc.Elements("List").FirstOrDefault(e => (string)e.Attribute("name") == Name);
if (listElement != null)
listElement.Remove();
});
return true;
}
return false;
}
} }
} }

34
ILSpy/Commands/OpenListCommand.cs

@ -0,0 +1,34 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// 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.
using System;
namespace ICSharpCode.ILSpy
{
[ExportMainMenuCommand(Menu = "_File", Header = "Open _List", MenuIcon = "Images/AssemblyList.png", MenuCategory = "Open", MenuOrder = 1.7)]
sealed class OpenListCommand : SimpleCommand
{
public override void Execute(object parameter)
{
OpenListDialog dlg = new OpenListDialog();
dlg.Owner = MainWindow.Instance;
if (dlg.ShowDialog() == true)
MainWindow.Instance.ShowAssemblyList(dlg.SelectedListName);
}
}
}

24
ILSpy/CreateListDialog.xaml

@ -0,0 +1,24 @@
<Window
x:Class="ICSharpCode.ILSpy.CreateListDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
Title="New list"
Style="{DynamicResource DialogWindow}"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Width="300"
Height="150"
FocusManager.FocusedElement="{Binding ElementName=listView}">
<Grid Margin="12,8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel>
<Label>Enter a list name:</Label>
<TextBox Margin="8,8" Name="ListName" TextChanged="TextBox_TextChanged"></TextBox>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="8,0">
<Button IsDefault="True" Margin="2,0" IsEnabled="False" Name="okButton" Click="OKButton_Click">Create</Button>
<Button IsCancel="True" Margin="2,0">Cancel</Button>
</StackPanel>
</Grid>
</Window>

49
ILSpy/CreateListDialog.xaml.cs

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
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;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Interaction logic for Create.xaml
/// </summary>
public partial class CreateListDialog : Window
{
public CreateListDialog()
{
InitializeComponent();
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
okButton.IsEnabled = !string.IsNullOrWhiteSpace(ListName.Text);
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(ListName.Text))
{
this.DialogResult = true;
}
}
public string NewListName
{
get
{
return ListName.Text;
}
}
}
}

12
ILSpy/ILSpy.csproj

@ -100,11 +100,15 @@
<Compile Include="CommandLineArguments.cs" /> <Compile Include="CommandLineArguments.cs" />
<Compile Include="Commands\ExitCommand.cs" /> <Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\CommandWrapper.cs" /> <Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="Commands\OpenListCommand.cs" />
<Compile Include="Controls\DockedPane.cs" /> <Compile Include="Controls\DockedPane.cs" />
<Compile Include="Commands\DecompileAllCommand.cs" /> <Compile Include="Commands\DecompileAllCommand.cs" />
<Compile Include="Commands\ExportCommandAttribute.cs" /> <Compile Include="Commands\ExportCommandAttribute.cs" />
<Compile Include="Controls\SearchBox.cs" /> <Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" /> <Compile Include="Controls\SortableGridViewColumn.cs" />
<Compile Include="CreateListDialog.xaml.cs">
<DependentUpon>CreateListDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Languages\CSharpLanguage.cs" /> <Compile Include="Languages\CSharpLanguage.cs" />
<Compile Include="DecompilationOptions.cs" /> <Compile Include="DecompilationOptions.cs" />
<Compile Include="ExtensionMethods.cs" /> <Compile Include="ExtensionMethods.cs" />
@ -138,6 +142,9 @@
<DependentUpon>ResourceStringTable.xaml</DependentUpon> <DependentUpon>ResourceStringTable.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="OpenListDialog.xaml.cs">
<DependentUpon>OpenListDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Options\DecompilerSettingsPanel.xaml.cs"> <Compile Include="Options\DecompilerSettingsPanel.xaml.cs">
<DependentUpon>DecompilerSettingsPanel.xaml</DependentUpon> <DependentUpon>DecompilerSettingsPanel.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
@ -262,8 +269,13 @@
<Page Include="Controls\SearchBoxStyle.xaml"> <Page Include="Controls\SearchBoxStyle.xaml">
<DependentUpon>SearchBox.cs</DependentUpon> <DependentUpon>SearchBox.cs</DependentUpon>
</Page> </Page>
<Page Include="CreateListDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml" /> <Page Include="MainWindow.xaml" />
<Page Include="OpenFromGacDialog.xaml" /> <Page Include="OpenFromGacDialog.xaml" />
<Page Include="OpenListDialog.xaml" />
<Page Include="Options\DecompilerSettingsPanel.xaml" /> <Page Include="Options\DecompilerSettingsPanel.xaml" />
<Page Include="Options\DisplaySettingsPanel.xaml" /> <Page Include="Options\DisplaySettingsPanel.xaml" />
<Page Include="Options\OptionsDialog.xaml" /> <Page Include="Options\OptionsDialog.xaml" />

48
ILSpy/MainWindow.xaml.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy
ILSpySettings spySettings; ILSpySettings spySettings;
internal SessionSettings sessionSettings; internal SessionSettings sessionSettings;
AssemblyListManager assemblyListManager; internal AssemblyListManager assemblyListManager;
AssemblyList assemblyList; AssemblyList assemblyList;
AssemblyListTreeNode assemblyListTreeNode; AssemblyListTreeNode assemblyListTreeNode;
@ -242,14 +242,29 @@ namespace ICSharpCode.ILSpy
{ {
if (args.NavigateTo != null) { if (args.NavigateTo != null) {
bool found = false; bool found = false;
foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) {
AssemblyDefinition def = asm.AssemblyDefinition; string namespaceName = args.NavigateTo.Substring(2);
if (def != null) { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) {
MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def.MainModule, args.NavigateTo); AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
if (mr != null) { if (asmNode != null) {
found = true; NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
JumpToReference(mr); if (nsNode != null) {
break; found = true;
SelectNode(nsNode);
break;
}
}
}
} else {
foreach (LoadedAssembly asm in commandLineLoadedAssemblies) {
AssemblyDefinition def = asm.AssemblyDefinition;
if (def != null) {
MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def.MainModule, args.NavigateTo);
if (mr != null) {
found = true;
JumpToReference(mr);
break;
}
} }
} }
} }
@ -323,6 +338,21 @@ namespace ICSharpCode.ILSpy
} }
#endregion #endregion
public void ShowAssemblyList(string name)
{
ILSpySettings settings = this.spySettings;
if (settings == null)
{
settings = ILSpySettings.Load();
}
AssemblyList list = this.assemblyListManager.LoadList(settings, name);
//Only load a new list when it is a different one
if (list.ListName != CurrentAssemblyList.ListName)
{
ShowAssemblyList(list);
}
}
void ShowAssemblyList(AssemblyList assemblyList) void ShowAssemblyList(AssemblyList assemblyList)
{ {
history.Clear(); history.Clear();

41
ILSpy/OpenListDialog.xaml

@ -0,0 +1,41 @@
<Window
x:Class="ICSharpCode.ILSpy.OpenListDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
Title="Open List"
Style="{DynamicResource DialogWindow}"
WindowStartupLocation="CenterOwner"
ResizeMode="CanResizeWithGrip"
MinWidth="380"
MinHeight="250"
Height="350"
Width="380"
FocusManager.FocusedElement="{Binding ElementName=listView}">
<Grid Margin="12,8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel>
<Label>Select a list:</Label>
</StackPanel>
<ListView Name="listView" Grid.Row="1" Margin="0, 8" controls:SortableGridViewColumn.SortMode="Automatic" SelectionChanged="ListView_SelectionChanged"
Loaded="listView_Loaded" SelectionMode="Single">
<ListView.View>
<GridView>
<controls:SortableGridViewColumn x:Name="nameColumn" Header="Name" DisplayMemberBinding="{Binding .}" />
</GridView>
</ListView.View>
</ListView>
<DockPanel Grid.Row="2">
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right">
<Button IsDefault="True" Margin="2,0" IsEnabled="False" Name="okButton" Click="OKButton_Click">Open</Button>
<Button IsCancel="True" Margin="2,0">Cancel</Button>
</StackPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" HorizontalAlignment="Left">
<Button Margin="2,0" Click="CreateButton_Click">Create</Button>
<Button Margin="2,0" IsEnabled="False" Name="removeButton" Click="RemoveButton_Click">Remove</Button>
</StackPanel>
</DockPanel>
</Grid>
</Window>

184
ILSpy/OpenListDialog.xaml.cs

@ -0,0 +1,184 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// 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.
using System.Windows;
using System.Windows.Controls;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Interaction logic for OpenListDialog.xaml
/// </summary>
public partial class OpenListDialog : Window
{
public const string DotNet4List = ".NET 4 (WPF)";
public const string DotNet35List = ".NET 3.5";
public const string ASPDotNetMVC3List = "ASP.NET (MVC3)";
AssemblyListManager manager;
public OpenListDialog()
{
InitializeComponent();
manager = MainWindow.Instance.assemblyListManager;
}
private void listView_Loaded(object sender, RoutedEventArgs e)
{
listView.ItemsSource = manager.AssemblyLists;
CreateDefaultAssemblyLists();
}
void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
okButton.IsEnabled = listView.SelectedItem != null;
removeButton.IsEnabled = listView.SelectedItem != null;
}
void OKButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
public string SelectedListName
{
get
{
return listView.SelectedItem.ToString();
}
}
private void CreateDefaultAssemblyLists()
{
if (!manager.AssemblyLists.Contains(DotNet4List))
{
AssemblyList dotnet4 = new AssemblyList(DotNet4List);
AddToList(dotnet4, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet4, "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(dotnet4, "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(dotnet4, "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(dotnet4, "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
if (dotnet4.assemblies.Count > 0)
{
manager.CreateList(dotnet4);
}
}
if (!manager.AssemblyLists.Contains(DotNet35List))
{
AssemblyList dotnet35 = new AssemblyList(DotNet35List);
AddToList(dotnet35, "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(dotnet35, "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(dotnet35, "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(dotnet35, "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
if (dotnet35.assemblies.Count > 0)
{
manager.CreateList(dotnet35);
}
}
if (!manager.AssemblyLists.Contains(ASPDotNetMVC3List))
{
AssemblyList mvc = new AssemblyList(ASPDotNetMVC3List);
AddToList(mvc, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(mvc, "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(mvc, "System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(mvc, "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(mvc, "System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
AddToList(mvc, "System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
AddToList(mvc, "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
AddToList(mvc, "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
if (mvc.assemblies.Count > 0)
{
manager.CreateList(mvc);
}
}
}
private void AddToList(AssemblyList list, string FullName)
{
AssemblyNameReference reference = AssemblyNameReference.Parse(FullName);
string file = GacInterop.FindAssemblyInNetGac(reference);
if (file != null)
list.OpenAssembly(file);
}
private void CreateButton_Click(object sender, RoutedEventArgs e)
{
CreateListDialog dlg = new CreateListDialog();
dlg.Owner = this;
dlg.Closing += (s, args) =>
{
if (dlg.DialogResult == true)
{
if (manager.AssemblyLists.Contains(dlg.NewListName))
{
args.Cancel = true;
MessageBox.Show("A list with the same name was found.", null, MessageBoxButton.OK);
}
}
};
if (dlg.ShowDialog() == true)
{
manager.CreateList(new AssemblyList(dlg.NewListName));
}
}
private void RemoveButton_Click(object sender, RoutedEventArgs e)
{
if (listView.SelectedItem != null)
manager.DeleteList(listView.SelectedItem.ToString());
}
}
}

18
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -139,6 +139,9 @@ namespace ICSharpCode.ILSpy.TreeNodes
get { return true; } get { return true; }
} }
/// <summary>
/// Finds the node for a top-level type.
/// </summary>
public TypeTreeNode FindTypeNode(TypeDefinition def) public TypeTreeNode FindTypeNode(TypeDefinition def)
{ {
if (def == null) if (def == null)
@ -151,6 +154,21 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
/// <summary>
/// Finds the node for a namespace.
/// </summary>
public NamespaceTreeNode FindNamespaceNode(string namespaceName)
{
if (string.IsNullOrEmpty(namespaceName))
return null;
EnsureLazyChildren();
NamespaceTreeNode node;
if (namespaces.TryGetValue(namespaceName, out node))
return node;
else
return null;
}
public override bool CanDrag(SharpTreeNode[] nodes) public override bool CanDrag(SharpTreeNode[] nodes)
{ {
return nodes.All(n => n is AssemblyTreeNode); return nodes.All(n => n is AssemblyTreeNode);

87
ILSpy/XmlDoc/XmlDocKeyProvider.cs

@ -48,11 +48,9 @@ namespace ICSharpCode.ILSpy.XmlDoc
b.Append("M:"); b.Append("M:");
AppendTypeName(b, member.DeclaringType); AppendTypeName(b, member.DeclaringType);
b.Append('.'); b.Append('.');
if (member.Name == ".ctor") b.Append(member.Name.Replace('.', '#'));
b.Append("#ctor");
else
b.Append(member.Name);
IList<ParameterDefinition> parameters; IList<ParameterDefinition> parameters;
TypeReference explicitReturnType = null;
if (member is PropertyDefinition) { if (member is PropertyDefinition) {
parameters = ((PropertyDefinition)member).Parameters; parameters = ((PropertyDefinition)member).Parameters;
} else if (member is MethodReference) { } else if (member is MethodReference) {
@ -62,6 +60,9 @@ namespace ICSharpCode.ILSpy.XmlDoc
b.Append(mr.GenericParameters.Count); b.Append(mr.GenericParameters.Count);
} }
parameters = mr.Parameters; parameters = mr.Parameters;
if (mr.Name == "op_Implicit" || mr.Name == "op_Explicit") {
explicitReturnType = mr.ReturnType;
}
} else { } else {
parameters = null; parameters = null;
} }
@ -73,6 +74,10 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
b.Append(')'); b.Append(')');
} }
if (explicitReturnType != null) {
b.Append('~');
AppendTypeName(b, explicitReturnType);
}
} }
return b.ToString(); return b.ToString();
} }
@ -85,27 +90,21 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
if (type is GenericInstanceType) { if (type is GenericInstanceType) {
GenericInstanceType giType = (GenericInstanceType)type; GenericInstanceType giType = (GenericInstanceType)type;
if (type.DeclaringType != null) { AppendTypeNameWithArguments(b, giType.ElementType, giType.GenericArguments);
AppendTypeName(b, type.DeclaringType);
b.Append('.');
} else if (!string.IsNullOrEmpty(type.Namespace)) {
b.Append(type.Namespace);
b.Append('.');
}
b.Append(NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name));
b.Append('{');
for (int i = 0; i < giType.GenericArguments.Count; i++) {
if (i > 0) b.Append(',');
AppendTypeName(b, giType.GenericArguments[i]);
}
b.Append('}');
} else if (type is TypeSpecification) { } else if (type is TypeSpecification) {
AppendTypeName(b, ((TypeSpecification)type).ElementType); AppendTypeName(b, ((TypeSpecification)type).ElementType);
ArrayType arrayType = type as ArrayType; ArrayType arrayType = type as ArrayType;
if (arrayType != null) { if (arrayType != null) {
b.Append('['); b.Append('[');
for (int i = 1; i < arrayType.Dimensions.Count; i++) { for (int i = 0; i < arrayType.Dimensions.Count; i++) {
b.Append(','); if (i > 0)
b.Append(',');
ArrayDimension ad = arrayType.Dimensions[i];
if (ad.IsSized) {
b.Append(ad.LowerBound);
b.Append(':');
b.Append(ad.UpperBound);
}
} }
b.Append(']'); b.Append(']');
} }
@ -115,7 +114,7 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
PointerType ptrType = type as PointerType; PointerType ptrType = type as PointerType;
if (ptrType != null) { if (ptrType != null) {
b.Append('*'); // TODO: is this correct? b.Append('*');
} }
} else { } else {
GenericParameter gp = type as GenericParameter; GenericParameter gp = type as GenericParameter;
@ -134,6 +133,32 @@ namespace ICSharpCode.ILSpy.XmlDoc
} }
} }
} }
static int AppendTypeNameWithArguments(StringBuilder b, TypeReference type, IList<TypeReference> genericArguments)
{
int outerTypeParameterCount = 0;
if (type.DeclaringType != null) {
TypeReference declType = type.DeclaringType;
outerTypeParameterCount = AppendTypeNameWithArguments(b, declType, genericArguments);
b.Append('.');
} else if (!string.IsNullOrEmpty(type.Namespace)) {
b.Append(type.Namespace);
b.Append('.');
}
int localTypeParameterCount = 0;
b.Append(NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out localTypeParameterCount));
if (localTypeParameterCount > 0) {
int totalTypeParameterCount = outerTypeParameterCount + localTypeParameterCount;
b.Append('{');
for (int i = outerTypeParameterCount; i < totalTypeParameterCount && i < genericArguments.Count; i++) {
if (i > outerTypeParameterCount) b.Append(',');
AppendTypeName(b, genericArguments[i]);
}
b.Append('}');
}
return outerTypeParameterCount + localTypeParameterCount;
}
#endregion #endregion
#region FindMemberByKey #region FindMemberByKey
@ -162,10 +187,10 @@ namespace ICSharpCode.ILSpy.XmlDoc
static MemberReference FindMember(ModuleDefinition module, string key, Func<TypeDefinition, IEnumerable<MemberReference>> memberSelector) static MemberReference FindMember(ModuleDefinition module, string key, Func<TypeDefinition, IEnumerable<MemberReference>> memberSelector)
{ {
Debug.WriteLine("Looking for member " + key); Debug.WriteLine("Looking for member " + key);
int pos = key.IndexOf('('); int parenPos = key.IndexOf('(');
int dotPos; int dotPos;
if (pos > 0) { if (parenPos > 0) {
dotPos = key.LastIndexOf('.', pos - 1, pos); dotPos = key.LastIndexOf('.', parenPos - 1, parenPos);
} else { } else {
dotPos = key.LastIndexOf('.'); dotPos = key.LastIndexOf('.');
} }
@ -173,14 +198,24 @@ namespace ICSharpCode.ILSpy.XmlDoc
TypeDefinition type = FindType(module, key.Substring(2, dotPos - 2)); TypeDefinition type = FindType(module, key.Substring(2, dotPos - 2));
if (type == null) if (type == null)
return null; return null;
Debug.WriteLine("Searching in type " + type.FullName); string shortName;
if (parenPos > 0) {
shortName = key.Substring(dotPos + 1, parenPos - (dotPos + 1));
} else {
shortName = key.Substring(dotPos + 1);
}
Debug.WriteLine("Searching in type {0} for {1}", type.FullName, shortName);
MemberReference shortNameMatch = null;
foreach (MemberReference member in memberSelector(type)) { foreach (MemberReference member in memberSelector(type)) {
string memberKey = GetKey(member); string memberKey = GetKey(member);
Debug.WriteLine(memberKey); Debug.WriteLine(memberKey);
if (memberKey == key) if (memberKey == key)
return member; return member;
if (shortName == member.Name.Replace('.', '#'))
shortNameMatch = member;
} }
return null; // if there's no match by ID string (key), return the match by name.
return shortNameMatch;
} }
static TypeDefinition FindType(ModuleDefinition module, string name) static TypeDefinition FindType(ModuleDefinition module, string name)

33
NRefactory/ICSharpCode.NRefactory.Tests/CSharp/InsertParenthesesVisitorTests.cs

@ -345,5 +345,38 @@ namespace ICSharpCode.NRefactory.CSharp
Assert.AreEqual("a && (b || c)", InsertRequired(expr)); Assert.AreEqual("a && (b || c)", InsertRequired(expr));
Assert.AreEqual("a && (b || c)", InsertReadable(expr)); Assert.AreEqual("a && (b || c)", InsertReadable(expr));
} }
[Test]
public void ArrayCreationInIndexer()
{
Expression expr = new IndexerExpression {
Target = new ArrayCreateExpression {
Type = new PrimitiveType("int"),
Arguments = { new PrimitiveExpression(1) }
},
Arguments = { new PrimitiveExpression(0) }
};
Assert.AreEqual("(new int[1]) [0]", InsertRequired(expr));
Assert.AreEqual("(new int[1]) [0]", InsertReadable(expr));
}
[Test]
public void ArrayCreationWithInitializerInIndexer()
{
Expression expr = new IndexerExpression {
Target = new ArrayCreateExpression {
Type = new PrimitiveType("int"),
Arguments = { new PrimitiveExpression(1) },
Initializer = new ArrayInitializerExpression {
Elements = { new PrimitiveExpression(42) }
}
},
Arguments = { new PrimitiveExpression(0) }
};
Assert.AreEqual("new int[1] { 42 } [0]", InsertRequired(expr));
Assert.AreEqual("(new int[1] { 42 }) [0]", InsertReadable(expr));
}
} }
} }

92
NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/ExpressionBuilder.cs

@ -1,92 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB.AstBuilder
{
/// <summary>
/// Extension methods for NRefactory.Dom.Expression.
/// </summary>
public static class ExpressionBuilder
{/*
public static SimpleNameExpression Identifier(string identifier)
{
return new SimpleNameExpression(identifier);
}
public static MemberReferenceExpression Member(this Expression targetObject, string memberName)
{
if (targetObject == null)
throw new ArgumentNullException("targetObject");
return new MemberReferenceExpression(targetObject, memberName);
}
public static InvocationExpression Call(this Expression callTarget, string methodName, params Expression[] arguments)
{
if (callTarget == null)
throw new ArgumentNullException("callTarget");
return Call(Member(callTarget, methodName), arguments);
}
public static InvocationExpression Call(this Expression callTarget, params Expression[] arguments)
{
if (callTarget == null)
throw new ArgumentNullException("callTarget");
if (arguments == null)
throw new ArgumentNullException("arguments");
return new InvocationExpression(callTarget, new List<Expression>(arguments));
}
public static ObjectCreateExpression New(this TypeReference createType, params Expression[] arguments)
{
if (createType == null)
throw new ArgumentNullException("createType");
if (arguments == null)
throw new ArgumentNullException("arguments");
return new ObjectCreateExpression(createType, new List<Expression>(arguments));
}
public static Expression CreateDefaultValueForType(TypeReference type)
{
if (type != null && !type.IsArrayType) {
switch (type.Type) {
case "System.SByte":
case "System.Byte":
case "System.Int16":
case "System.UInt16":
case "System.Int32":
case "System.UInt32":
case "System.Int64":
case "System.UInt64":
case "System.Single":
case "System.Double":
return new PrimitiveExpression(0, "0");
case "System.Char":
return new PrimitiveExpression('\0', "'\\0'");
case "System.Object":
case "System.String":
return new PrimitiveExpression(null, "null");
case "System.Boolean":
return new PrimitiveExpression(false, "false");
default:
return new DefaultValueExpression(type);
}
} else {
return new PrimitiveExpression(null, "null");
}
}
/// <summary>
/// Just calls the BinaryOperatorExpression constructor,
/// but being an extension method; this allows for a nicer
/// infix syntax in some cases.
/// </summary>
public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right)
{
return new BinaryOperatorExpression(left, op, right);
}*/
}
}

55
NRefactory/ICSharpCode.NRefactory.VB/AstBuilder/StatementBuilder.cs

@ -1,55 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB.AstBuilder
{
/// <summary>
/// Extension methods for NRefactory.Dom.Expression.
/// </summary>
// public static class StatementBuilder
// {
// public static void AddStatement(this BlockStatement block, Statement statement)
// {
// if (block == null)
// throw new ArgumentNullException("block");
// if (statement == null)
// throw new ArgumentNullException("statement");
// block.AddChild(statement);
// statement.Parent = block;
// }
//
// public static void AddStatement(this BlockStatement block, Expression expressionStatement)
// {
// if (expressionStatement == null)
// throw new ArgumentNullException("expressionStatement");
// AddStatement(block, new ExpressionStatement(expressionStatement));
// }
//
// public static void Throw(this BlockStatement block, Expression expression)
// {
// if (expression == null)
// throw new ArgumentNullException("expression");
// AddStatement(block, new ThrowStatement(expression));
// }
//
// public static void Return(this BlockStatement block, Expression expression)
// {
// if (expression == null)
// throw new ArgumentNullException("expression");
// AddStatement(block, new ReturnStatement(expression));
// }
//
// public static void Assign(this BlockStatement block, Expression left, Expression right)
// {
// if (left == null)
// throw new ArgumentNullException("left");
// if (right == null)
// throw new ArgumentNullException("right");
// AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
// }
// }
}

6
NRefactory/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -45,8 +45,6 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AstBuilder\ExpressionBuilder.cs" />
<Compile Include="AstBuilder\StatementBuilder.cs" />
<Compile Include="Ast\AstLocation.cs" /> <Compile Include="Ast\AstLocation.cs" />
<Compile Include="Ast\AstNode.cs" /> <Compile Include="Ast\AstNode.cs" />
<Compile Include="Ast\AstNodeCollection.cs" /> <Compile Include="Ast\AstNodeCollection.cs" />
@ -180,14 +178,10 @@
<Compile Include="PrettyPrinter\VBNet\VBNetPrettyPrintOptions.cs" /> <Compile Include="PrettyPrinter\VBNet\VBNetPrettyPrintOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VBParser.cs" /> <Compile Include="VBParser.cs" />
<Compile Include="Visitors\AbstractAstTransformer.cs" />
<Compile Include="Visitors\AbstractAstVisitor.cs" />
<Compile Include="Visitors\CSharpToVBConverterVisitor.cs" /> <Compile Include="Visitors\CSharpToVBConverterVisitor.cs" />
<Compile Include="Visitors\NodeTrackingAstVisitor.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Ast" /> <Folder Include="Ast" />
<Folder Include="AstBuilder" />
<Folder Include="Ast\General" /> <Folder Include="Ast\General" />
<Folder Include="Ast\GlobalScope" /> <Folder Include="Ast\GlobalScope" />
<Folder Include="Ast\Expressions" /> <Folder Include="Ast\Expressions" />

11
NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.NRefactory.VB
StartNode(parameterDeclaration); StartNode(parameterDeclaration);
WriteAttributes(parameterDeclaration.Attributes); WriteAttributes(parameterDeclaration.Attributes);
WriteModifiers(parameterDeclaration.ModifierTokens); WriteModifiers(parameterDeclaration.ModifierTokens);
WriteIdentifier(parameterDeclaration.Name.Name); parameterDeclaration.Name.AcceptVisitor(this, data);
if (!parameterDeclaration.Type.IsNull) { if (!parameterDeclaration.Type.IsNull) {
WriteKeyword("As"); WriteKeyword("As");
parameterDeclaration.Type.AcceptVisitor(this, data); parameterDeclaration.Type.AcceptVisitor(this, data);
@ -1053,7 +1053,7 @@ namespace ICSharpCode.NRefactory.VB
#endregion #endregion
#region IsKeyword Test #region IsKeyword Test
static readonly HashSet<string> unconditionalKeywords = new HashSet<string> { static readonly HashSet<string> unconditionalKeywords = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
"AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte", "AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte",
"ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CInt", "Class", "CLng", "ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CInt", "Class", "CLng",
"CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt", "CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt",
@ -1705,6 +1705,11 @@ namespace ICSharpCode.NRefactory.VB
WriteCommaSeparatedListInParenthesis(objectCreationExpression.Arguments, false); WriteCommaSeparatedListInParenthesis(objectCreationExpression.Arguments, false);
if (!objectCreationExpression.Initializer.IsNull) { if (!objectCreationExpression.Initializer.IsNull) {
Space(); Space();
if (objectCreationExpression.Initializer.Elements.Any(x => x is FieldInitializerExpression))
WriteKeyword("With");
else
WriteKeyword("From");
Space();
objectCreationExpression.Initializer.AcceptVisitor(this, data); objectCreationExpression.Initializer.AcceptVisitor(this, data);
} }
@ -1870,7 +1875,7 @@ namespace ICSharpCode.NRefactory.VB
{ {
StartNode(fieldInitializerExpression); StartNode(fieldInitializerExpression);
if (fieldInitializerExpression.IsKey) { if (fieldInitializerExpression.IsKey && fieldInitializerExpression.Parent is AnonymousObjectCreationExpression) {
WriteKeyword("Key"); WriteKeyword("Key");
Space(); Space();
} }

2078
NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstTransformer.cs

File diff suppressed because it is too large Load Diff

1156
NRefactory/ICSharpCode.NRefactory.VB/Visitors/AbstractAstVisitor.cs

File diff suppressed because it is too large Load Diff

1266
NRefactory/ICSharpCode.NRefactory.VB/Visitors/NodeTrackingAstVisitor.cs

File diff suppressed because it is too large Load Diff

5
NRefactory/ICSharpCode.NRefactory/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

@ -132,6 +132,11 @@ namespace ICSharpCode.NRefactory.CSharp
public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
{ {
ParenthesizeIfRequired(indexerExpression.Target, Primary); ParenthesizeIfRequired(indexerExpression.Target, Primary);
ArrayCreateExpression ace = indexerExpression.Target as ArrayCreateExpression;
if (ace != null && (InsertParenthesesForReadability || ace.Initializer.IsNull)) {
// require parentheses for "(new int[1])[0]"
Parenthesize(indexerExpression.Target);
}
return base.VisitIndexerExpression(indexerExpression, data); return base.VisitIndexerExpression(indexerExpression, data);
} }

4
doc/Command Line.txt

@ -25,10 +25,12 @@ Available options:
/clearList Clears the assembly list before loading the specified assemblies. /clearList Clears the assembly list before loading the specified assemblies.
[Note: Assembly Lists are not yet implemented] [Note: Assembly Lists are not yet implemented]
/navigateTo:tag Navigates to the member specified by the given XML documentation tag. /navigateTo:tag Navigates to the member specified by the given ID string.
The member is searched for only in the assemblies specified on the command line. The member is searched for only in the assemblies specified on the command line.
Example: 'ILSpy ILSpy.exe /navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments' Example: 'ILSpy ILSpy.exe /navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments'
The syntax of ID strings is described in appendix A of the C# language specification.
/language:name Selects the specified language. /language:name Selects the specified language.
Example: 'ILSpy /language:C#' or 'ILSpy /language:IL' Example: 'ILSpy /language:C#' or 'ILSpy /language:IL'

Loading…
Cancel
Save