Parse/Refactor C# via C# code - c#

Is there any libraries from Microsoft or from Mono project that allow you to do sweeping changes on a C# code base via code? Anything in Cecil for this? I think Cecil would only allow you to work at the bytecode level - anything to work on the language level?
I have already identified the issues I'd like to correct. Just could use some help with the Search/Replace in a C# syntax-aware fashion.

You should look at Roslyn - it's only in the preview stage at the moment, but it sounds like just what you want. (There are various blog posts about it, including this introductory one.)

There's a reasonably powerful search and replace in Resharper if that's appropriate to your situation.
http://blogs.jetbrains.com/dotnet/2010/04/introducing-resharper-50-structural-search-and-replace/

Related

An alternative for .NET Script Editor

I am developing an API for some application. And I need to attach there a script engine to make it possible to invoke API from script.
It would be quite nice to have autocomplete, syntax highlight and debug in scripts.
I have found this solution: http://www.codeproject.com/Articles/27744/Net-Script-Editor-C-Vb-net-Mini-IDE
But there are a lot of bugs.
Does anybody have any ideas of alternative solution?
LinqPad has many of the features you are looking for - some of them cost a small extra fee, but it's probably worth the fee!
http://www.linqpad.net/
Snippet Compiler is a nice tool.
You don't mention which language your scripts are in, but based on your other question about debuggers I'll assume you are using IronPython.
The most complete (free/open source) option that I've been able to find is SharpDevelop. It includes all of the features you've mentioned for IronPython as well as a debugger. It is open source and includes many useful extensibility points, so it should provide a good starting point to fix bugs and add additional language support if needed (provided your use conforms to its license terms).
If your situation requires use beyond what is provided by the LGPL then the best choice (though not standalone or free) is to extend Visual Studio (there's already an extension for IronPython though I'm unsure if it supports debugging).
It doesn't sound like you're looking to do much, if any, development of your own for this but if I'm misreading your question then there are some editor controls available that provide the features listed (and then some) for .NET (not exhaustive):
Scintilla.Net
AvalonEdit (used by SharpDevelop)
An example of a project that uses Scintilla.Net is Peter.
You can try with SharpDevelop .

Convert QT/C++ to C#

This might seem a little ridiculous, but as some of you here may already know, I'm converting an application written in C++ to C#.
I've noticed that a lot of the code uses references to objects like "QObject", "QWidget", or "QFrame."
Because of this, I'm not quite sure if I should look up the source for QT and port the basic structure of that into a bunch of C# classes which essentially mimic the same functionality, or if there's any kind of framework out there which does the same thing and can be used as a replacement for this.
Also, could someone please explain to me what a slide and a slot is, and what it is I could do to mimic this in C# as well? I'm thinking delegates, but I'm not sure...
Have a look at Qyoto it might just drop in to you code with a few modifications.
The page that Oded recommended also gave a link to qt4dotnet - have you tried this?
If you can't use one of these bindings, you will probably want to start investigating how to port all Q* references in the codebase to WinForms, WPF, or Silverlight (depending on your application needs)

C# to VB.NET Code Converter

I need a C# to VB.NET code converter, and I'm willing to pay. I want something that's ultra convenient, as I want to reduce the amount of copy/paste that I have to do... so could anybody give me some tips to what is out there? I want processing in bulk too, and to support the latest operations (LINQ, new VB inline-function support and all).
Thanks.
I have Tangible Software's Instant VB that I use. It seams to work very well. It will do LINQ, Full projects, files and snippets.
http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB.html
Online:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
One roundabout way to go about it is to disassemble an assembly using RedGate's .NET Reflector, and export the VB/C# code.
Reflector can loose some of the code flavor in the conversion/dissassembly, but I've always been able to get it to compile.
I've used several free tools online, but have found their correctness to be spotty at best. The one #Jeremy refers to is fairly decent, but lacks some recent .NET features. Odds are it will meet your needs.

WPF UserControl to DLL Programmatically

I am generating a WPF UserControl in code that I would like to save as a DLL for use in a different application. The process of saving the DLL needs to be fully automated. Would it be better to try to do this with System.Reflection or by shelling out to csc? Or, is there an even better way to do this?
I think you should use CodeCompiler for that purpose. There is no need in Reflection or shelling out csc as all the required support is already provided within .net framework.
Check out the Microsoft Support article: "How to programmatically compile code using C# compiler". Also take a look at the "System.CodeDom.Compiler" namespace at MSDN.
Also you will need to perform some googling in order to find samples that suite your needs. Code generation had been discussed a lot so you won't have problems finding samples.
You might be also interested in automating of your source code generation so T4 is also worth looking at. Refer to Oleg Sych blog to find out all details towards T4 generation.

How can I create my custom Shell Context Handlers for Windows?

Problem
Language: C# 2.0 or later
I would like to register context handlers to create menues when the user right clicks certain files (in my case *.eic). What is the procedure to register, unregister (clean up) and handle events (clicks) from these menues?
I have a clue it's something to do with the windows registry, but considering how much stuff there is in .net, I wouldn't be surprised if there are handy methods to do this clean and easy.
Code snippets, website references, comments are all good. Please toss them at me.
Update
Obviously there is a slight problem creating context menues in managed languages, as several users have commented. Is there any other preferred way of achieving the same behaviour, or should I spend time looking into these workarounds? I don't mind doing that at all, I'm glad people have put effort into making this possible - but I still want to know if there is a "proper/clean" way of achieving this.
Resist writing Shell Extensions in managed languages - there are a multitude of things that could go bang if you pursue this route.
Have a browse through this thread for more details. It contains links to do it if really want, and sagely advice of why it can be done, but shouldn't.
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/1428326d-7950-42b4-ad94-8e962124043e/
You're back to unmanaged C/C++ as your only real tools here.
This is not a good idea because of potential dependency issues between different versions of the .NET Framework. Your shell extension could be expecting one version, while a different version may have already been loaded by the application that's currently running.
This thread contains a good summary of the situation.
While others already mentioned that writing shell extensions in pure .NET is a bad idea due to framework conflicts, you should still note that:
There are 3rd party drivers out there (see Eldos or LogicNP) that do the unmanaged side for you, allowing you to write managed code that talks to the native driver, thus preventing shell-related CLR version conflicts.
A recent MSDN article mentioned that Microsoft has solved this problem for the CoreCLR, as used by Silverlight. They've accomplished this by allowing multiple versions of the CLR to run in the same process, thus fixing the problem. The author further stated that this fix in Silverlight will be rolled into future versions of the full CLR. (Meaning, in the future, it will be quite feasible to write shell extensions in managed code.)
I've done them before in C#. It ends up being a hell of a lot harder than it should be. Once you get the boilerplate code down, though, it is easy to roll out new items. I followed this link:
Link To Info
As the prior comments mention, it isn't the best idea to write shell extensions in managed languages, but I thought I'd share an Open Source project that is doing just that :)
ShellGlue is a managed shell extension that is actually quite helpful. The source also might be helpful to you if you're interested in pursuing writing a shell extension in C/C++.
Aside from the caveats that have been mentioned concerning the implementation of shell extensions in managed code, what you'd basically need to do is the following:
First, create a COM component in C# that implements the IShellExtInit IContextMenu interfaces. How to create COM components in C# is described here. How to implement the necessary interfaces is described in this article. While the description is for a C++ implementation, you can apply that knowledge to you C# version.
Your COM component will have GUID called the Class-ID or CLSID. You need to register that ID with your file type as a context-menu shell extension:
HKEY_CLASSES_ROOT\.eic\ShellEx\ContextMenuHandlers\MyShellExt
(Default) -> {YOUR-COMPONENTS-CLSID}
Also make sure that you registered your component correctly as described in the C# COM tutorial. You should find it in the registry under
HKEY_CLASSES_ROOT\CLSID\{YOUR-COMPONENTS-CLSID}
InprocServer32
(Default) -> C:\WINDOWS\system32\mscoree.dll
Class -> YourImplClass
assembly -> YourAssembly, version=..., Culture=neutral, PublicKey=...
...
Good luck...
As others have pointed out, shell extensions are not practical in windows development currently.
I asked a similar question recently which was answered with a link to a guide to do exactly what I wanted to do

Categories

Resources