Typed Dataset Generator

Last week Brendan Tompkins was complaining that the typed dataset generation process in .NET was not “open” enough. In my comemnt I said that typed dataset generation WAS extensible via CodeDOM manipulation (in all fairness to Brendan this is possibly not the easiest API to work with, but the extensibility hooks are there). I had a little demo application that I had written which did this, so I polished it up and put it on GotDotNet. It automatically generates typed datasets (or optionally Xml Schema files) for all the stored procedures in your MS SQL Server database using the same framework classes that xsd.exe uses (so it DOES actually serve some purpose as well as showing how to manipulate CodeDOM object graphs). In the past I have found typed datasets to be great, but keeping the stored procedure result-sets ,XML Schema and generated code synchronized was annoying. This utility removes that problem.

Comments

Brendan Tompkins
Very Cool! First thing in the morning, I’m going to dive into your demo! I love using Typed DataSets, and when I heard DonXML was down on them, my heart sunk.. This looks like a great answer to skeptics!
18/05/2004 9:40:00 AM
JosephCooney
Since I wrote this demo I’ve been looking at the typed dataset generator in the ADO.NET power toys on GotDotNet. I think I might update my utility to include the option to use their library too as it seems quite good.
18/05/2004 10:02:00 AM
Marcel van Pinxteren
I made an updated version and put in on CodeProject.com.
By being able to inherit from a typed dataset, you can put whatever validation or other custom behavior you want in your dataset.
24/11/2004 8:10:00 AM

»

Generics Presentation - Lessons Learned

Dominic did a great presentation on generics at the local users group last night. There were a number of things that I thought he did very well: Simple slide layout - I love those flashy slide backgrounds, but Dominic went for a simple white background and a few subtle font colours, and I think it worked well. Ditching VS.NET - Instead of using VS.NET he wrote all his demos from scratch in EMACS (with no syntax hilighting), and complied with the command line tools. »

More XPath Syntax Hilighting

I’ve been making a few more changes to my XPath syntax hilighting I mentioned earlier. If you recall the previous example XPath location path abbreviations like @foo were being expanded to their full text like attribute::foo. This might be a little weird/annoying, so the parser has been modified to ‘remember’ if it was using the abbreviated syntax or not. This means that (apart from whitespace) there is a pretty high correlation between what you type and the hilighted text that appears. I’ve also added a few enhancements - for example user defined functions are hilighted in a different colour to regular functions (in the example below coalesce() is a user-defined function while concat() and string() are built-in). I’m still not sure how all this is going to finish up - I haven’t given any thought to namespaces except write a whole bunch of //TODO comments, and there is still the whole issue of adding Intellisense ™.

Comments

JosephCooney
XPath Syntax hilighting - when pain persists see your local parser writer
26/06/2004 12:57:00 AM

»

Go with the Flow

I was just over at Pragmatic Dave’s weblog getting ready to do some mental push-ups when I saw this post on Flow: it sounds pretty awesome. Stu Halloway (formerly of Developmentor) is involved.Their site does not have a lot of technical details. They seemed to be targeting OSX as a platform initially which seemed a bit odd. Still, it looks very cool. »

Syntax Hilighting XPath Expressions

I love XPath. My first GotDotNet sample was an XPath expression tester. It is a very simple application. It can be quite helpful when working out expressions, but one thing that I always wanted to add (but never got around to) was syntax hilighting. After a while mucking around with the ROTOR XPath implementation I’m starting to be able to do the syntax hilighting.



As you can see from the screen shot I’m not actually hiligthing the text as it is typed, I’m doing that in a seperate text box for now. The eventual .plan is for it to all happen in a single text box, possibly with auto-completeion like Visual Studio Intellisense ™. One problem with the SSCLI XPath implementation (for the use I’m putting it to anyway) is that it doesn’t care about maintaining the exact text used to create the expression - it’s only concerned with building an abstract syntax tree of nodes so certain things are “thrown out” during the parse. I’m not actually sure if the current way I’m going about things is going to work, but hopefully I can have fun trying. When/If I get it working I will post an update on GotDotNet.

Comments

secretGeek

Speaking of syntax highlighting… what about using some of Dominic Cooney’s parsing code? I hear he is not the worst programmer in the family…


13/04/2004 10:43:00 AM
JosephCooney
Yes, I’m racing to finish it before Dominic automates the whole process. On the bright side - If he keeps going the way he is I won’t have to wait until ROTOR 2 to get an XQuery implementation to do syntax hilighting for me.
13/04/2004 10:47:00 AM

»

Comfortably Enum

Fellow .NET junkie A Henry P. Erich III posted an entry on parsing enums. Scott Galloway noted in the comments that Henry should probably check out Enum.IsDefined. I’d like to second that. The way it currently stands Henry’s code could return enum values that don’t exist in the list of current enum values. For example if you’ve defined an enumeration Food with the values Sausage = 1, Eggs = 2, Cheese = 3 and Herrings = 4 it could return a value outside that range.

How is this possible? Aren’t enums a list of predefined values, that can only be one of those values? Well…..no. In the code below we create an enum called TestEnum with the values Foo = 1, Bar = 2 and Undefined = 3. We use a modified version of Henry’s code and pass it values “Foo“, “Bar“, “ThisWontWork“ and “99“. The first 3 work as you would expect - foo and bar are parsed without incident. “ThisWontWork“ throws an exception which is caught and returns a “default“ value of TestEnum.Undefined. The last one returns a brand new TestEnum value with an underlying numeric value of 99. It is not in our existing list of enums. After I saw this I made sure all my methods were checking IsDefined for any enum arguemnts they receive, and all my switch statements that use an enum as an argument have a default case that throws an exception of some sort.

1using System;
2
3namespace ComfortablyEnum
4{
5 class EnumTest
6 {
7  public enum TestEnum
8  {
9   Foo = 1,
10   Bar = 2,
11   Undefined = 3
12  }
13
14  [STAThread]
15  static void Main(string[] args)
16  {
17   TestEnum parsedItem = ParseEnum(“Foo”);
18   PerformSomeActionOnEnumValue(parsedItem);
19
20   parsedItem = ParseEnum(“Bar”);
21   PerformSomeActionOnEnumValue(parsedItem);
22
23   parsedItem = ParseEnum(“ThisWontWork”);
24   PerformSomeActionOnEnumValue(parsedItem);
25
26   parsedItem = ParseEnum(“99”); // what about this?

27   PerformSomeActionOnEnumValue(parsedItem);
28
29  }
30
31  static TestEnum ParseEnum(string itemToParse)
32  {
33   TestEnum returnValue;
34   try
35   {
36    // Validate the enum with a try/catch

37    returnValue = (TestEnum)Enum.Parse(typeof(TestEnum), itemToParse, true);
38   }
39
40   catch
41   {
42    // Set to default or whatever other handling you want.

43    returnValue = TestEnum.Undefined;
44   }
45   return returnValue;
46  }
47
48  static void PerformSomeActionOnEnumValue(TestEnum argument)
49  {
50   switch (argument)
51   {
52    case TestEnum.Foo:
53     Console.WriteLine(“Take some action on foo enum value…”);
54     break;
55
56    case TestEnum.Bar:
57     Console.WriteLine(“Take some action on bar enum value…”);
58     break;
59
60    case TestEnum.Undefined:
61     Console.WriteLine(“Take some action based on Undefined enum value…”);
62     break;
63
64    default:
65     Console.WriteLine(“How is this possible….there are only 3 values for this enum?”);
66     break;
67   }
68  }
69 }
70}
71

Comments

Henry Erich III
And here is a MS article, the info we are talking about is down at the bottom.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconvaluetypeusageguidelines.asp

Also, how do you get your code to display so neatly?
8/04/2004 12:44:00 AM
JosephCooney
Hi Henry - that is a good link. Here is the utility I used to format that code.

http://www.squishyweb.com/ware/products.asp?q=squishysyntax
8/04/2004 12:52:00 AM
Henry Erich III
Thanks Joseph! Have a fun day!
8/04/2004 1:22:00 AM
Scott Galloway
One slight issue with Enum.IsDefined whjen compared with Enum.Parse is that the latter allows for case insensitivity whilst the former does not. Normally this isn’t a problem (I have tended to stich to a single case for Enum items - usually upper case). One nice way round this is to use Title case only (so first letter upper, rest lower). You can then use System.Globalization.TextInfo.ToTitleCase() to convert your input string to the correct case (http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemGlobalizationTextInfoClassToTitleCaseTopic.asp?frame=true)
8/04/2004 7:40:00 PM
secretGeek
Great title! (i.e. ‘Comfortably Enum’)
love it!
13/04/2004 10:41:00 AM

»

Async Callbacks in ASP.NET 2.0 VS 2005 CTP Release

The good news is that my GotDotNet sample on async callbacks in ASP.NET 2.0 runs fine under the CTP release of ASP.NET 2.0 (v2.0.4031). The bad news is that there has not been any changes made to the RaiseCallbackEvent method in the ICallbackEventHandler interface (which I considered to be a bit limited). Speaking to Darren a while ago, he thought that I might be the problem rather than the method signature. He said it was fairly consistent with some other method signatures on similar interfaces in System. »