Reflection IT Blog

Benieuwd naar de laatste ontwikkelingen rondom software ontwikkeling en Reflection IT? Onze slimme koppen delen regelmatig hun kennis en ervaring. Zo weet jij wat er speelt!

csharp tagged Blog posts

Trace LINQ to SQL Queries

04-Dec-2007

ASP.NET Tracing is a powerful mechanism. LINQ to SQL doesn't support it out of the box. The DataContext class however has a Log property which can be set to a TextWriter object. This TextWriter object writes all SQL queries which are executed.

I have created a small class which derives from TextWriter to write all SQL queries to the System.Diagnostics.Trace class. I found out that I only had to override the WriteLine(string) and Write(string) methods.

The easiest way to assign a new TextToTraceWriter to the Log property of the DataContext object is by implementing the partial OnCreated() method in a partial class. See the following example in which also the Trace Category is set.

NotificationFormTraceListener Assembly

26-Nov-2007

During development, you can use the output methods of the Debug class to display messages in the Output window of the Visual Studio 2005 integrated development environment (IDE). For example:

' Visual Basic
Trace.WriteLine("Hello World!")
Debug.WriteLine("Hello World!")

// C#
Trace.WriteLine("Hello World!");
Debug.WriteLine("Hello World!");

Each of these examples will display "Hello World!" in the Output window when the application is run in the debugger.

The .NET TraceListners monitor trace and debug output. You use TraceListners to redirect this output to a specific medium. There are 3 TraceListners available: DefaultTraceListener, EventLogTraceListener and TextWriterTraceListener.

ConvertSelectedTextToAssociatedLabel Macro

09-Oct-2007

I have created a new Visual Studio 2005 Macro which can be used to convert a literal text to an asp:Label that is associated to the next control. You first have to select the text and then Run the ConvertSelectedTextToAssociatedLabel Macro. In the example below the text Age: is selected.

The result is an asp:Label with the correct Text and AssociatedControlID attributes.

Download Zipfile

My First XNA Game

27-May-2007

I finally found some time to play with XNA. I learned a lot from Rob Miles at TechEd 2006. He has some great samples on his website. Rob will also be presenting about this subject on the DevDays 2007 in the Netherlands. Fun is guaranteed.

My first game is a remake of a game I build 20 years ago on my Commodore 64. You must move around a bouncing ball using your joystick. The ball may not collide with the flying birds. It took me only a few hours to build and it was great fun.

XNA - Drawing Text in XNA

Updated my DAL article!

17-May-2006

I have updated my DAL article which I wrote late 2002. This article was one of my first aricles and needed an update. The download project now also contains a .NET 2.0 project. It uses the new TraceSource class for tracing purposes. I hope you like it.

Hooray!

19-Feb-2006

I have just received mail from Pearson VUE informing me that have passed the Beta Exam 70-528 TS: Microsoft .NET Framework 2.0 - Web-Based Client Development (called 71-528 while it's in Beta). I also received a free Voucher for a next exam, thanks guys.

On Friday I will try the Beta Exam 70-551 UPGRADE: MCAD Skills to MCPD Web Developer by Using the Microsoft .NET Framework. One week later I will try the Beta Exam70-552 UPGRADE: MCAD Skills to MCPD Windows Developer by Using the Microsoft .NET Framework . Wish me luck.

New VS2005 Macros

18-Nov-2005

Three years ago I have written some useful Visual Studio 2003 macros: SortCode and CreateProperty. With the introduction of VS2005 it was time to upgrade them.

The new SortCode macro also supports VB.NET 2005. Totally new is the EncapsulateAllNonPrivateFields macro. It creates properties get/set for all non private (public, protected, internal) fields. By using the CodeDom I managed to supports VB.NET and C#.

Example

After running the marco the 3 fields are private and there are 3 extra properties.

Avalon and ClickOnce demo

23-Sep-2005

I have build my first Windows Presentation Foundation (WPF) application. It is a remake of my WinForms Minesweeper game. Go to the ClickOnce publisher page and install Avalon Minesweeper.

Make sure you have the Microsoft Pre-Release Software WinFX Runtime Components - September Community Technology Preview (CTP) installed on your computer.

To run this sample you must add 'https://www.mydotnetplayground.nl/WpfMinesweeper' to your Trusted Sites in Internet Explorer.

UPDATE 1-1-2006: Moved to my own provider and updated to the December CTP.

C# 3.0 looks like Smalltak

14-Sep-2005

Many years ago I programmed in Smalltalk (Enfin which later became ObjectStudio). I have always liked it although it was not very programmer friendly (no IntelliSense). I have just wachted this C# 3.0 Language Enhancements in action video. The shown Extension Methods feature realy looks like the Secondary Class files of Smalltalk. Nice to see them back, they where very handy.

In the following example I have added the 'IsPrime()' method to the 'Int32' type. The 'this' keyword in front of the 'number' parameter of the IsPrime() method did the real trick. This makes it an Extension Method.

class Program {
   &nbspstaticvoid Main(string[]args){
   &nbsp   &nbspConsole.WriteLine(5.IsPrime());// true
   &nbsp   &nbspConsole.WriteLine(9.IsPrime());// false
   &nbsp   &nbspConsole.WriteLine(23.IsPrime());// true
   &nbsp}
}

staticclass Extensions {

   &nbsppublicstaticbool IsPrime(thisintnumber){
   &nbsp   &nbspif(number==1||number==2||number==3){
   &nbsp   &nbsp   &nbspreturntrue;
   &nbsp   &nbsp}
   &nbsp   &nbspif((number%2)==0){
   &nbsp   &nbsp   &nbspreturnfalse;
   &nbsp   &nbsp}
   &nbsp   &nbspintsqrt=(int)Math.Sqrt(number);
   &nbsp   &nbspfor(int t =3; t <=sqrt; t = t +2){
   &nbsp   &nbsp   &nbspif(number% t ==0){
   &nbsp   &nbsp   &nbsp   &nbspreturnfalse;
   &nbsp   &nbsp   &nbsp}
   &nbsp   &nbsp}
   &nbsp   &nbspreturntrue;
   &nbsp}
}

Get in touch

Met dit formulier kunt u informatie over een In-Company of Small-Group training aanvragen. U kunt in het bericht aangeven welke training u wilt, voor hoeveel personen, wanneer deze verzorgd moet worden en op welke locatie. Wij nemen vervolgens contact met u op.

U kunt ons ook bereiken via telefoonnummer +31 (0)493-688810 of per mail training@reflectionit.nl.