Chris Pietschmann

husband, father, hacker, entrepreneur, futurist, innovator, autodidact

NAVIGATION - SEARCH

Odd .NET Namespace Scoping Causes Compile-Time Exception

This isn’t really a bug in the .NET compilers, but it sure is an interesting namespace scoping issue that could easily be encountered. If this teaches you anything, be it that you should never name a nested namespace level the same name as one of its parents in the hierarchy. In C# First here’s the Compile Time Exception that I was getting: The type or namespace name ‘Data’ does not exist in namespace ‘MyApp.Data.MyApp’ (are you missing an assembly reference?) At first I was like “What do yo... [More]

Simple Port Scanner Written in VB.NET 2003/2008

I was looking over some of the old prototypes I've written in the past, and I can across a Simple Port Scanner that I originally wrote in VB.NET 2003. I originally wrote this back in 2004 (I think), and even posted a compiled version on my website that I have since removed/deleted. So, since it's just sitting on my hard drive collecting virtual dust, I thought I'd post it here in case anyone else can find it usefull. This Port Scanner implements Multi-T... [More]

A Couple VB.NET Language Tips for C# Developers

Originally, I started out as a Visual Basic developer, and have since moved mostly to C#. However, when doing consulting work, I do need to cross back and forth quite often. Here are a couple VB.NET tips that you probably aren't aware of if you're mostly a C# developer. Some VB.NET developers may not even know about then either. Null Coalesce Null Coalescing is really simple in C#: [code:c#] // If "someValue" is Null then set "i" to 0 (zero) // otherwise set it to the value of "someValue" in... [More]

.NET: Why aren't Private Abstract methods allowed?

Sometimes when creating base objects you want to create methods that are overridable by object that inherit the base object, but keep the methods from being public. However, the compiler throws an exceptions when you try to define a method as "Private Abstract". Why doesn't the compiler like "Private Abstract" methods? The reason for this is Private methods can not be overriden. So, essentially the Abstract is useless if the method is Private. How can I create a "Private" method that's a... [More]

Introduction to LINQ

What is LINQ? LINQ (Language INtegrated Query) is more than just a new method of embedding SQL queries within code. It allows to to perform Strongly Typed queries on any kind of data, just as long as the collection of data implements the IEnumerable interface. The most important part is "Language Integrated". This allows you to more easily write queries in C# 3.0 and VB 9.0 such as:   IEnumerable<Person> filterExample1 = from Person in people     &nbs... [More]

2008 Microsoft Launch Event and Free Software

On February 27th in Los Angeles, CA, Microsoft is kicking off a series of "HEROES happen {here}" launch events nationwide. These are the official launch events for Windows Server 2008, Visual Studio 2008, and SQL Server 2008. And, one of the best parts is everyone that takes part in one of the events will be taking home a promotional kit with versions of all three products. Since the Milwaukee event isn't until May 8th, I've registered for the Chicago event on March 11th. I don't want to w... [More]

.NET: How to Alias Namespaces and Data Types

One of the little known features of .NET is that you can give complete namespaces and data types alias's that you can reference them with in code. Aliasing Data Types For this example we'll give a different name to the integer data type: In VB.NET: Imports MyInteger = System.Int32; In C#: using MyInteger = System.Int32; Now to use the alias in code: In VB.NET: Public myVariable As MyInteger = 4; In C#: MyInteger myVariable = 4; Aliasing Namespaces For this example, lets assume ... [More]

Microsoft to release .NET Framework 3.5 as Shared Source!

Scott Guthrie announced on his blog today, that Microsoft will be releasing the source code for .NET 3.5 as shared source under the Microsoft Reference License (MS-RL). You will also be able to enable debugging support within Visual Studio 2008 for the .NET Framework. This is really cool. I have always used .NET Reflector to peek into the source of the framework, but now I'll actually be able to look at the code itself. More Info:Releasing the Source Code for the .NET Framework Libraries ... [More]

Parallel FX Library: Optimize your code for Multi-Core machines

I was reading the October 2007 edition of MSDN Magazine and came across an article titled "Parallel Performance: Optimize Managed Code For Multi-Core Machines." At first I thought that this was just another article explaining how to use the ThreadPool in .NET to improve the performance of you app, but they are actually talking about the new Parallel FX Library that is about to reach its first CTP. What is this Parallel FX Library? Simple... It's a .NET library that is designed to make is much ... [More]

Creating an IDE? Use the Visual Studio 2008 shell as your base.

Starting with Visual Studio 2008, you'll be able to use the Visual Studio 2008 Shell as the starting point to create your own development tools. The Visual Studio Shell will be available as part of the Visual Studio 2008 SDK, but I believe we'll have to wait until VS'08 RTM's before we'll be able to play with creating apps using the shell. On the Visual Studio 2008 Shell page, there's a screenshot of Floorplan designer built using the VS'08 Shell. This looks like a really neat feature that... [More]

C#/VB.NET: Extension Methods

Over a year ago I posted a question about doing a SQL-like IN operation in .NET. Here's the examples I posted of how it could work: Dim arrNames() AS String = New Array{"CHRIS", "TOM", "TYLER"} If strName IN arrNames Then    'do something End If Now, this would be a powerful feature since you wouldn't be required to write code that loops through the array or collection. Well, I saw some good news today posted by Scott Guthrie. ... [More]

Visual Studio 2005 Add-In: Get the total number of line of code in your solution

Here's a Visual Studio 2005 Add-In that shows you the total lines of code within your solution/project. It also show the breakout of each individual file. Currently it doesn't include line counts from files within any WebSites that are included inside your solution. But overall this Addin is simple and to the point. Besides, it's open source so you can fix/modify it in any way you'd like. Visual Studio 2005 Line Counter Add-In + Source Code 

VB.NET: RegEx Syntax Highlighting RichTextBox

Here is a version of my code for syntax highlighting in a RichTextBox that incorporates regular expressions.   Download RegEx Syntax Highlighting RichTextBox Source Code Source Code Listed: Public Class SyntaxRTB Inherits System.Windows.Forms.RichTextBox Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As Integer) As Integer Private Declare Function LockWindowUpdate Lib... [More]

C# .NET: Convert System.Drawing.Color to HTML color

Here is a small example of how to convert a System.Drawing.Color to the HTML color format (Hex value or HTML color name value) and back. System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#F5F7F8"); String strHtmlColor = System.Drawing.ColorTranslator.ToHtml(c);

.NET Framework - Check if Windows booted in Normal or Safe Mode

Heres a really small code sample on how to check which mode Windows was booted up in (Normal or Safe Mode). This works in .NET 1.x and 2.0.   1 'This code checks to see which mode Windows has booted up in.  2 Select Case System.Windows.Forms.SystemInformation.BootMode  3 Case BootMode.FailSafe  4      'The computer was booted using only the basic files and drivers.  5      'This is the same as Safe Mode  6 Case BootMode.FailS... [More]

VB.NET: Syntax Highlighting in a RichTextBox control

This last weekend I expirimented a little bit with extending the functionality of the RichTextBox control. Below you'll find an example of a small class that enherits from the RichTextBox control and allows you to implement syntax highlighting (with the use of a couple Win32 API call to smooth over the process of course.) The code pretty much speaks for itself.   Public Class SyntaxRTB    Inherits System.Windows.Forms.RichTextBox    Private Declar... [More]

VB.NET: Make a Form semi-transparent when moving and resizing it

Here's a little VB.NET code snippet that I wrote to make a Form semi-transparent when moving and resizing it. I think this is a neat little effect to add to an application.   Public Class frmTransparentMoveResize Inherits System.Windows.Forms.Form Private _OpacityResize As Double = 0.5 Private _OpacityMove As Double = 0.5 Private _OpacityOriginal As Double Private Const WM_NCLBUTTONDOWN As Long = &HA1 Private Const WM_NCLBUTTONUP As Long = &... [More]

Write to the Event Log in .NET (VB.NET and C#.NET)

It is as simple as this to write to the Windows Event Log in .NET Declaration: Imports System.Diagnostics Code: Public Function WriteToEventLog(ByVal Entry As String, _ Optional ByVal AppName As String = "APlusFeeCalc", _ Optional ByVal EventType As EventLogEntryType = EventLogEntryType.Information, _ Optional ByVal LogName As String = "Application") As Boolean      Dim objEventLog As New EventLog      Try... [More]