Convert c# form to C++.Net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Has anyone written a utility to convert a C# form to C++.net?
i.e. to convert "using System.Data" to "using namespace System::Data" etc
 
You can compile then decompile your code from C# to C++.NET using Reflector:

http://www.aisto.com/roeder/dotnet/Download.aspx?File=Reflector

C++ AddIn

http://www.testdriven.net/downloads/Reflector.McppLanguage.dll

Steps:

Once downloaded open Reflector
Click the View menu and select the Add-Ins... item.
Click on Add and select the McppLanguage.dll you downloaded.



1. Compile your program either a DLL or EXE
2. Open it with Reflector
3. Select the language you want your source code decompiled in.
4. Right click on the class your want to decompile.

Hope this helps,

Yama Kamyar
 
thanks, but unfortunately Reflector doesn't cover Managed C++.

Thinking about it though, I'm not sure that we really want to write code in
the Managed c++ syntax.
We will probably just write our C# code outside our managed C++ project and
include the assemblies.
(We are using managed C++ in order to write all new dialogs as win forms. We
can't throw all the c++ code away although I wish we could.)
 
What do you mean? It works fine for me.... If I have code written in C# I can
decompile it in managed C++ but in order for that to work I need to reference
the McppLanguage DLL.

A little test:


The Iterator design pattern written in C#:

namespace Iterator
{
internal abstract class AbstractCollection
{
// Methods
protected AbstractCollection();
public abstract Iterator.Iterator CreateIterator();
}

internal abstract class AbstractIterator
{
// Methods
protected AbstractIterator();
public abstract Item CurrentItem();
public abstract Item First();
public abstract bool IsDone();
public abstract Item Next();
}

internal class Collection : AbstractCollection
{
// Methods
public Collection();
public override Iterator.Iterator CreateIterator();

// Properties
public int Count { get; }
public object this[int index] { get; set; }

// Fields
private ArrayList items;
}

public class Form1 : Form
{
// Methods
public Form1();
protected override void Dispose(bool disposing);
private void Form1_Load(object sender, EventArgs e);
private void InitializeComponent();
[STAThread]
private static void Main();

// Fields
private Container components;
private TextBox txtIteratorText;
}

internal class Item
{
// Methods
public Item(string name);

// Properties
public string Name { get; }

// Fields
private string name;
}

internal class Iterator : AbstractIterator
{
// Methods
public Iterator(Collection collection);
public override Item CurrentItem();
public override Item First();
public override bool IsDone();
public override Item Next();

// Properties
public int Step { get; set; }

// Fields
private Collection collection;
private int current;
private int step;
}
}


Compiled then decompiled to C++ using Reflector:


namespace Iterator
{
private __gc abstract class AbstractCollection
{
// Methods
protected: AbstractCollection();
public: abstract Iterator::Iterator __gc * CreateIterator();
};

private __gc abstract class AbstractIterator
{
// Methods
protected: AbstractIterator();
public: abstract Iterator::Item __gc * CurrentItem();
public: abstract Iterator::Item __gc * First();
public: abstract System::Boolean IsDone();
public: abstract Iterator::Item __gc * Next();
};

[System::Reflection::DefaultMember(S"Item")]
private __gc class Collection : public Iterator::AbstractCollection
{
// Methods
public: Collection();
public: override Iterator::Iterator __gc * CreateIterator();

// Properties
public: __property System::Int32 get_Count();
public: __property System::Object __gc * get_Item(System::Int32
index);public: __property void set_Item(System::Int32 index, System::Object
__gc * value);

// Fields
private: System::Collections::ArrayList __gc * items;
};

public __gc class Form1 : public System::Windows::Forms::Form
{
// Methods
public: Form1();
protected: override void Dispose(System::Boolean disposing);
private: void Form1_Load(System::Object __gc * sender,
System::EventArgs __gc * e);
private: void InitializeComponent();
[System::STAThread]
private: static void Main();

// Fields
private: System::ComponentModel::Container __gc * components;
private: System::Windows::Forms::TextBox __gc * txtIteratorText;
};

private __gc class Item
{
// Methods
public: Item(System::String __gc * name);

// Properties
public: __property System::String __gc * get_Name();

// Fields
private: System::String __gc * name;
};

private __gc class Iterator : public Iterator::AbstractIterator
{
// Methods
public: Iterator(Iterator::Collection __gc * collection);
public: override Iterator::Item __gc * CurrentItem();
public: override Iterator::Item __gc * First();
public: override System::Boolean IsDone();
public: override Iterator::Item __gc * Next();

// Properties
public: __property System::Int32 get_Step();public: __property
void set_Step(System::Int32 value);

// Fields
private: Iterator::Collection __gc * collection;
private: System::Int32 current;
private: System::Int32 step;
};
}


Any questions?

Yama
 
Back
Top