Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5616 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
33 changed files with 119 additions and 715 deletions
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("")] |
||||
[assembly: AssemblyCopyright("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")] |
||||
|
||||
@ -1,181 +0,0 @@
@@ -1,181 +0,0 @@
|
||||
// SharpDevelop samples
|
||||
// Copyright (c) 2006, AlphaSierraPapa
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this list
|
||||
// of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the SharpDevelop team nor the names of its contributors may be used to
|
||||
// endorse or promote products derived from this software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.IO; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.NRefactory.PrettyPrinter; |
||||
|
||||
namespace NRefactoryExample |
||||
{ |
||||
public class MainForm : System.Windows.Forms.Form |
||||
{ |
||||
public MainForm() |
||||
{ |
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
InitializeComponent(); |
||||
} |
||||
|
||||
[STAThread] |
||||
public static void Main(string[] args) |
||||
{ |
||||
Application.EnableVisualStyles(); |
||||
Application.Run(new MainForm()); |
||||
} |
||||
|
||||
#region Windows Forms Designer generated code
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent() |
||||
{ |
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); |
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); |
||||
this.inputTextBox = new System.Windows.Forms.TextBox(); |
||||
this.panel1 = new System.Windows.Forms.Panel(); |
||||
this.runButton = new System.Windows.Forms.Button(); |
||||
this.outputTextBox = new System.Windows.Forms.TextBox(); |
||||
this.splitContainer1.Panel1.SuspendLayout(); |
||||
this.splitContainer1.Panel2.SuspendLayout(); |
||||
this.splitContainer1.SuspendLayout(); |
||||
this.panel1.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.splitContainer1.Location = new System.Drawing.Point(0, 0); |
||||
this.splitContainer1.Name = "splitContainer1"; |
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.inputTextBox); |
||||
this.splitContainer1.Panel1.Controls.Add(this.panel1); |
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.outputTextBox); |
||||
this.splitContainer1.Size = new System.Drawing.Size(804, 422); |
||||
this.splitContainer1.SplitterDistance = 394; |
||||
this.splitContainer1.TabIndex = 0; |
||||
//
|
||||
// inputTextBox
|
||||
//
|
||||
this.inputTextBox.AcceptsReturn = true; |
||||
this.inputTextBox.AcceptsTab = true; |
||||
this.inputTextBox.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.inputTextBox.Location = new System.Drawing.Point(0, 0); |
||||
this.inputTextBox.Multiline = true; |
||||
this.inputTextBox.Name = "inputTextBox"; |
||||
this.inputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; |
||||
this.inputTextBox.Size = new System.Drawing.Size(394, 372); |
||||
this.inputTextBox.TabIndex = 1; |
||||
this.inputTextBox.Text = resources.GetString("inputTextBox.Text"); |
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.runButton); |
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; |
||||
this.panel1.Location = new System.Drawing.Point(0, 372); |
||||
this.panel1.Name = "panel1"; |
||||
this.panel1.Size = new System.Drawing.Size(394, 50); |
||||
this.panel1.TabIndex = 0; |
||||
//
|
||||
// runButton
|
||||
//
|
||||
this.runButton.Anchor = System.Windows.Forms.AnchorStyles.None; |
||||
this.runButton.Location = new System.Drawing.Point(128, 15); |
||||
this.runButton.Name = "runButton"; |
||||
this.runButton.Size = new System.Drawing.Size(131, 23); |
||||
this.runButton.TabIndex = 0; |
||||
this.runButton.Text = "Run"; |
||||
this.runButton.UseCompatibleTextRendering = true; |
||||
this.runButton.UseVisualStyleBackColor = true; |
||||
this.runButton.Click += new System.EventHandler(this.RunButtonClick); |
||||
//
|
||||
// outputTextBox
|
||||
//
|
||||
this.outputTextBox.Dock = System.Windows.Forms.DockStyle.Fill; |
||||
this.outputTextBox.Location = new System.Drawing.Point(0, 0); |
||||
this.outputTextBox.Multiline = true; |
||||
this.outputTextBox.Name = "outputTextBox"; |
||||
this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; |
||||
this.outputTextBox.Size = new System.Drawing.Size(406, 422); |
||||
this.outputTextBox.TabIndex = 0; |
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
||||
this.ClientSize = new System.Drawing.Size(804, 422); |
||||
this.Controls.Add(this.splitContainer1); |
||||
this.Name = "MainForm"; |
||||
this.Text = "NRefactory Example"; |
||||
this.splitContainer1.Panel1.ResumeLayout(false); |
||||
this.splitContainer1.Panel1.PerformLayout(); |
||||
this.splitContainer1.Panel2.ResumeLayout(false); |
||||
this.splitContainer1.Panel2.PerformLayout(); |
||||
this.splitContainer1.ResumeLayout(false); |
||||
this.panel1.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.Button runButton; |
||||
private System.Windows.Forms.TextBox outputTextBox; |
||||
private System.Windows.Forms.TextBox inputTextBox; |
||||
private System.Windows.Forms.Panel panel1; |
||||
private System.Windows.Forms.SplitContainer splitContainer1; |
||||
#endregion
|
||||
|
||||
void RunButtonClick(object sender, EventArgs e) |
||||
{ |
||||
StringReader input = new StringReader(inputTextBox.Text); |
||||
IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, input); |
||||
parser.Parse(); |
||||
if (parser.Errors.Count > 0) { |
||||
outputTextBox.Text = parser.Errors.ErrorOutput; |
||||
return; |
||||
} |
||||
CompilationUnit cu = parser.CompilationUnit; |
||||
|
||||
cu.AcceptVisitor(new WrapperGeneratorVisitor(), null); |
||||
|
||||
IOutputAstVisitor output = new CSharpOutputVisitor(); //new VBNetOutputVisitor();
|
||||
// SpecialNodesInserter will re-insert the comments into the generated code
|
||||
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), output)) { |
||||
cu.AcceptVisitor(output, null); |
||||
} |
||||
outputTextBox.Text = output.Text; |
||||
} |
||||
} |
||||
} |
||||
@ -1,184 +0,0 @@
@@ -1,184 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<data name="inputTextBox.Text" xml:space="preserve"> |
||||
<value>// <file> |
||||
// <copyright see="prj:///doc/copyright.txt"/> |
||||
// <license see="prj:///doc/license.txt"/> |
||||
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/> |
||||
// <version>$Revision: 698 $</version> |
||||
// </file> |
||||
|
||||
namespace Debugger.Interop.CorDebug |
||||
{ |
||||
using System; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
[ComImport, Guid("3D6F5F63-7538-11D3-8D5B-00104B35E7EF"), ComConversionLoss, InterfaceType((short) 1)] |
||||
public interface ICorDebugAppDomain : ICorDebugController |
||||
{ |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void Stop([In] uint dwTimeoutIgnored); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void Continue([In] int fIsOutOfBand); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void IsRunning(out int pbRunning); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void HasQueuedCallbacks([In, MarshalAs(UnmanagedType.Interface)] ICorDebugThread pThread, out int pbQueued); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void EnumerateThreads([MarshalAs(UnmanagedType.Interface)] out ICorDebugThreadEnum ppThreads); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void SetAllThreadsDebugState([In] CorDebugThreadState state, [In, MarshalAs(UnmanagedType.Interface)] ICorDebugThread pExceptThisThread); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void Detach(); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void Terminate([In] uint exitCode); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void CanCommitChanges([In] uint cSnapshots, [In, MarshalAs(UnmanagedType.Interface)] ref ICorDebugEditAndContinueSnapshot pSnapshots, [MarshalAs(UnmanagedType.Interface)] out ICorDebugErrorInfoEnum pError); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void CommitChanges([In] uint cSnapshots, [In, MarshalAs(UnmanagedType.Interface)] ref ICorDebugEditAndContinueSnapshot pSnapshots, [MarshalAs(UnmanagedType.Interface)] out ICorDebugErrorInfoEnum pError); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void GetProcess([MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void EnumerateAssemblies([MarshalAs(UnmanagedType.Interface)] out ICorDebugAssemblyEnum ppAssemblies); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void GetModuleFromMetaDataInterface([In, MarshalAs(UnmanagedType.IUnknown)] object pIMetaData, [MarshalAs(UnmanagedType.Interface)] out ICorDebugModule ppModule); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void EnumerateBreakpoints([MarshalAs(UnmanagedType.Interface)] out ICorDebugBreakpointEnum ppBreakpoints); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void EnumerateSteppers([MarshalAs(UnmanagedType.Interface)] out ICorDebugStepperEnum ppSteppers); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void IsAttached(out int pbAttached); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void GetName([In] uint cchName, out uint pcchName, [Out] IntPtr szName); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void GetObject([MarshalAs(UnmanagedType.Interface)] out ICorDebugValue ppObject); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void Attach(); |
||||
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] |
||||
void GetID(out uint pId); |
||||
} |
||||
} |
||||
</value> |
||||
</data> |
||||
<metadata name="outputTextBox.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> |
||||
<value>True</value> |
||||
</metadata> |
||||
</root> |
||||
@ -1,46 +0,0 @@
@@ -1,46 +0,0 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<OutputType>WinExe</OutputType> |
||||
<RootNamespace>NRefactoryExample</RootNamespace> |
||||
<AssemblyName>NRefactoryExample</AssemblyName> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{5C8AF075-BB4A-4D24-BE69-46057C1B0107}</ProjectGuid> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<Optimize>False</Optimize> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<Optimize>True</Optimize> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="ICSharpCode.NRefactory"> |
||||
<HintPath>..\..\bin\ICSharpCode.NRefactory.dll</HintPath> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="MainForm.cs" /> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<EmbeddedResource Include="MainForm.resx"> |
||||
<DependentUpon>MainForm.cs</DependentUpon> |
||||
</EmbeddedResource> |
||||
<Compile Include="WrapperGeneratorVisitor.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
||||
@ -1,16 +0,0 @@
@@ -1,16 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00 |
||||
# SharpDevelop 2.0.0.704 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryExample", "NRefactoryExample.csproj", "{5C8AF075-BB4A-4D24-BE69-46057C1B0107}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{5C8AF075-BB4A-4D24-BE69-46057C1B0107}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{5C8AF075-BB4A-4D24-BE69-46057C1B0107}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{5C8AF075-BB4A-4D24-BE69-46057C1B0107}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{5C8AF075-BB4A-4D24-BE69-46057C1B0107}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
EndGlobalSection |
||||
EndGlobal |
||||
@ -1,144 +0,0 @@
@@ -1,144 +0,0 @@
|
||||
// SharpDevelop samples
|
||||
// Copyright (c) 2006, AlphaSierraPapa
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this list
|
||||
// of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the SharpDevelop team nor the names of its contributors may be used to
|
||||
// endorse or promote products derived from this software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS
|
||||
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace NRefactoryExample |
||||
{ |
||||
public class WrapperGeneratorVisitor : ICSharpCode.NRefactory.Visitors.AbstractAstVisitor |
||||
{ |
||||
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) |
||||
{ |
||||
base.VisitTypeDeclaration(typeDeclaration, data); // visit methods
|
||||
typeDeclaration.Attributes.Clear(); |
||||
typeDeclaration.BaseTypes.Clear(); |
||||
|
||||
// add constructor accepting the wrapped object and the field holding the object
|
||||
FieldDeclaration fd = new FieldDeclaration(null, // no attributes
|
||||
new TypeReference(typeDeclaration.Name), |
||||
Modifiers.Private); |
||||
fd.Fields.Add(new VariableDeclaration("wrappedObject")); |
||||
typeDeclaration.AddChild(fd); |
||||
|
||||
typeDeclaration.Name += "Wrapper"; |
||||
if (typeDeclaration.Type == ClassType.Interface) { |
||||
typeDeclaration.Type = ClassType.Class; |
||||
typeDeclaration.Name = typeDeclaration.Name.Substring(1); |
||||
} |
||||
ConstructorDeclaration cd = new ConstructorDeclaration(typeDeclaration.Name, |
||||
Modifiers.Public, |
||||
new List<ParameterDeclarationExpression>(), |
||||
null); |
||||
cd.Parameters.Add(new ParameterDeclarationExpression(fd.TypeReference, |
||||
"wrappedObject")); |
||||
// this.wrappedObject = wrappedObject;
|
||||
Expression fieldReference = new MemberReferenceExpression(new ThisReferenceExpression(), |
||||
"wrappedObject"); |
||||
Expression assignment = new AssignmentExpression(fieldReference, |
||||
AssignmentOperatorType.Assign, |
||||
new IdentifierExpression("wrappedObject")); |
||||
cd.Body = new BlockStatement(); |
||||
cd.Body.AddChild(new ExpressionStatement(assignment)); |
||||
typeDeclaration.AddChild(cd); |
||||
|
||||
for (int i = 0; i < typeDeclaration.Children.Count; i++) { |
||||
object child = typeDeclaration.Children[i]; |
||||
if (child is MethodDeclaration) { |
||||
MethodDeclaration method = (MethodDeclaration)child; |
||||
if (method.Parameters.Count == 0 && |
||||
(method.Name.StartsWith("Is") || method.Name.StartsWith("Get"))) |
||||
{ |
||||
// replace the method with a property
|
||||
PropertyDeclaration prop = new PropertyDeclaration(method.Modifier, |
||||
method.Attributes, |
||||
method.Name, |
||||
null); |
||||
prop.TypeReference = method.TypeReference; |
||||
prop.GetRegion = new PropertyGetRegion(method.Body, null); |
||||
typeDeclaration.Children[i] = prop; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) |
||||
{ |
||||
base.VisitMethodDeclaration(methodDeclaration, data); // visit parameters
|
||||
methodDeclaration.Attributes.Clear(); |
||||
methodDeclaration.Body = new BlockStatement(); |
||||
methodDeclaration.Modifier = Modifiers.Public; |
||||
|
||||
if (methodDeclaration.Parameters.Count > 0) { |
||||
ParameterDeclarationExpression lastParameter = methodDeclaration.Parameters[methodDeclaration.Parameters.Count - 1]; |
||||
if (lastParameter.ParamModifier == ParameterModifiers.Out) { |
||||
methodDeclaration.TypeReference = lastParameter.TypeReference; |
||||
methodDeclaration.Parameters.RemoveAt(methodDeclaration.Parameters.Count - 1); |
||||
|
||||
VariableDeclaration tmpVarDecl = new VariableDeclaration("tmp"); |
||||
tmpVarDecl.TypeReference = methodDeclaration.TypeReference; |
||||
methodDeclaration.Body.AddChild(new LocalVariableDeclaration(tmpVarDecl)); |
||||
|
||||
IdentifierExpression tmpIdent = new IdentifierExpression("tmp"); |
||||
InvocationExpression ie = CreateMethodCall(methodDeclaration); |
||||
ie.Arguments.Add(new DirectionExpression(FieldDirection.Out, tmpIdent)); |
||||
methodDeclaration.Body.AddChild(new ExpressionStatement(ie)); |
||||
|
||||
methodDeclaration.Body.AddChild(new ReturnStatement(tmpIdent)); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
methodDeclaration.Body.AddChild(new ExpressionStatement(CreateMethodCall(methodDeclaration))); |
||||
return null; |
||||
} |
||||
static InvocationExpression CreateMethodCall(MethodDeclaration method) |
||||
{ |
||||
IdentifierExpression wrappedObject = new IdentifierExpression("wrappedObject"); |
||||
MemberReferenceExpression methodName = new MemberReferenceExpression(wrappedObject, method.Name); |
||||
InvocationExpression ie = new InvocationExpression(methodName, null); |
||||
foreach (ParameterDeclarationExpression param in method.Parameters) { |
||||
Expression expr = new IdentifierExpression(param.ParameterName); |
||||
if (param.ParamModifier == ParameterModifiers.Ref) { |
||||
expr = new DirectionExpression(FieldDirection.Ref, expr); |
||||
} |
||||
ie.Arguments.Add(expr); |
||||
} |
||||
return ie; |
||||
} |
||||
|
||||
|
||||
public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) |
||||
{ |
||||
parameterDeclarationExpression.Attributes.Clear(); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue