Sunday, October 31, 2004

My. Wrapper for C# et. All

VB.Net 2005 has a new feature called "MY". My provides a quick access path to a lot of useful parts of the .net frame work. C# does not implement this feature however you can import the VB.Net dll and expose these capabilities (most of them) to your c# application.

OurSharp is an My. wrapper in c#. It is a small class that does some basic wrapping of some of the My. Objects. I named it our "Our" because in contrast to VB.net's "MY" this is accessible to all .net languages.

HOW TO USE:
1. Add a reference to Microsoft.VisualBasic.Dll
2. Add "Using Our;" to the top of all source files you want to use this in.
3. To use the My/Our functionality type Our. and select a object from the codecompletion window

The following My classes have been implemented:

Application
Computer
User

The other classes in VB.net MY are dynamically generated as you code - so a VS.Net addin would be required to get that done --- Maybe in the future.

The Source file is posted here

Sunday, October 24, 2004

DALHelperPlus - New

I recently posted DALHelperPlus.
This is a rebuild of the original DALHelper.aspx developed by Alex Lowe.

The original was appealing in its simple ness - it was a simple aspx page that would list all available stored procedures and it would put together a method that you would just have to paste into your DAL module. No external libraries needed (if you wanted you could choose an option to attach a parameter builder library but it was not the default and not required) All you did was choose your procedure – choose your return type (Dataset/DataReader) – Choose your language (C#/VB) and hit generate – you were done.

I looked at several other generators; most of them required other moving parts for example the stored procedure application block etc… This however was fast efficient and easy to use.

I used to have an instance of ASP.NET web matrix with the page open running in the background and I would just have to alt-tab to get access to it. However my webmatrix install recently got corrupted – and I could not (easily) run it in VS.net. So I decided to port the code over to a (always available) win forms based app.

I started playing with the code and I kept all of the database retrieval and parameter parsing from the original. However the code generation part I redid using the .net CodeDOM. The CodeDOM is a real pain in the neck to program against. It is very verbose and long winded; I almost gave up after 2 or 3 days. But then I found Refly a codeDom wrapper by Jonathan de Halleux that makes codedom programming much easier.

Using the CodeDOM brought another benefit. Where as the original used string building to build 2 different versions for vb.net and c# - here I only had to implement it once using a codedom tree. Further more, the app checks the machine.config file for all available .net compilers and allows you to generate the code for any one of them (you select the language from a drop down). On my machine I have c#,vb.net,javascript.net,J# I am also planning on playing around with Delphi 2005 (Diamodback) when it comes out and I will have a ready made Delphi code generator.

Another key feature of this app is the ability to control where DB connections come from - they can be built from connection strings (global/Local/Embeded/Resource Files) or from code snippets or from connection parameters passed on the command line - this all can be chosen from a drop down box.

You can also specify how you want the return values. Of course there is DataReader and DataSet - but there is also DataTable ,ArrayList (the first column of the resultset), HashTable ( First Column = second column) and primitive types such as int,float bool, (string) which return the first column of the first row typecasted as the appropriate type.

At first the app did not support OUTPUT parameters - that was because Refly did not support ByRef/Ref parameter calling - However a quick email to Jonathan got that fixed and OUTPUT parameters are now supported.

Besides for a desktop application I have also integrated the generation engine as a VS.NET plugin (VS.NET makes it so easy) and the generated code will get written directly to where the caret is in the open document.

You can download the current version (1.1) here.

I am also thinking about opening up a got dot net workspace for this.


This page is powered by Blogger. Isn't yours?