New Project: Gregor.Media
Sunday, November 5, 2006
I'm delighted to welcome a new project in the Gregor.NET application framework: Gregor.Media is the latest entry.
It's a general-purpose content rendering engine, leveraging the available text generation features, and using the .NET Console code interpreter heavily. Hopefully, it will push the framework to new directions.
In some way, I see all the things I've put my hands on so far - data access, code generation, code interpretation, text editing, WebEdit.NET with its extensible storages and views - finally coming together.
Remember my musings about Data Access and Strong Typing? This was about dynamically constructing generic types (tuples, in this case) from schema information returned from a database, but doing so with .NET Console. This time, implementing Gregor.Media, I came again to face the issue of mapping relational data to objects. The approach now isn't so all-automatic, but with the new C# language features, well see for yourself:
// general code, one of several generic overloads void ReadTable<T0, T1>(string sTableName, string sColumn0, string sColumn1, VoidCallback<T0, T1> cb){ using(IDataReader reader = this.ExecuteReader(sTableName, sColumn0, sColumn1)){ while(reader.Read()){ T0 v0 = (T0) this.GetValue(reader, sColumn0); T1 v1 = (T1) this.GetValue(reader, sColumn1); cb(v0, v1); } } } // client code void ReadArtists(){ this.ReadTable<int, string>( "Artist", "ArtistId", "Name", delegate(int id, string sName){ CArtist artist = new CArtist(id, sName); m_Artists.Add(artist, artist.Name); } ); }
This isn't DLinq-like simplicity, but it's reasonably concise.