Tag | C Posts

Let's say I have a base class that requires inheriting classes to implement a specific interface. Is there a keyword or attribute I can put on my base class to tell inheriting classes that they must implement a specific interface? Or do I have to implement the interface in my base class, then also implement the interface in inheriting classes and override the base implementation? Basically, I want to know if there is a cleaner way of accomplishing this public interface ICar { void UnlockCar(); void ...
As a display of how non-creative I am, I redesigned timhibbard.com this weekend. The new master page concept with ASP .NET 2.0 is really cool. Using a master page, I linked the Where's Tim API to show data from Where's Tim on the top of each page. Using AjaxPro and a little JavaScript, it updates every 15 seconds. Other than that, it's pretty boring :) Technorati tags: ASP .NET, C#, timhibbard.com, Where's Tim, Web design, AjaxPro ...
Cursor on Target (CoT) is an effort by military and governmental branches, FFRDCs (federally funded research and development corporations) and private companies to standardize an electronic portable data format to define location based data. I am the biggest geo-geek that I know, so obviously I was very interested when they contacted me about implementing their format into Where's Tim. These guys have done a great job of making a simple schema (12 required fields) that is easy to implement. I blogged ...
I love using Interfaces. They are great for three reasons: They enforce that your code implements specific functionality You can pass around interfaces in your code and any object that implements that interface can be used as a parameter Visual Studio automatically populates the methods signatures in a class that implements you interface I wish there was more an interface could do. Like enforce a method to handle a specific type of exception. Maybe it could be done with attributes. Something that ...
I try to maintain 100% code coverage in my non-UI classes, especially my state objects that just hold data. I recently ran into a situation that I'm having trouble writing an automated test for. We have a ContactInformation class that holds information about how to contact a person (home phone, cell phone, email), and in that class I have a .SendEmail and .VisitWebSite methods: public void SendEmail() { if (!string.IsNullOrEmpty(_ema... { System.Diagnostics.Process.... ...
I agree with Dru's comment on my post yesterday about overriding Equals(). I now want to implement a static function into my objects that will compare two objects. Again, I'm stuck between two ways of doing it. I could accept specific object types (static bool Equals(MyObject a, MyObject b)) or just accept an object type and cast it (static bool Equals(object a, object b)). I'm leaning towards the latter way as it allows me to define that method into the interface that all my objects already implement. ...
The ToolStripManager is a great way to save the position of toolbars on your WinForm apps. More info here. It works a little bit differently with ClickOnce applications, but it is an easy fix. Just set the key to a unique string. The key would probably have to be unique for the entire machine, but I'm not sure about that. The code looks like this: void formValidateBatch_FormClosi... sender, FormClosingEventArgs e) { ToolStripManager.SaveSettin... ...
This code snippet will return a generic list of DateTime containing the dates between a starting date and ending date: private List<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate) { if (StartingDate > EndingDate) { return null; } List<DateTime> rv = new List<DateTime>(); DateTime tmpDate = StartingDate; do { rv.Add(tmpDate); tmpDate = tmpDate.AddDays(1); } while (tmpDate <= EndingDate); return rv; } To view this code in action, copy and paste the following ...
I updated my article of the class to extract constants from a database for clean code freaks like me that want every field name to be defined by a constant. The original post is here. The code is here. Technorati tags: C#, code comments, .NET, Database ...
I blogged the other day about a class I wrote to help manage a VPN connection. Since then, I've made a couple changes and updated the article to reflect the code changes. -Created an overloaded, parameterless StartManaging method to make it easier to start in a new thread-Listened to the PowerModeChanged event and paused the timer if the computer is coming back from standby-Cleaned up a few issues-Added code comments The class code is here. If anybody wants to see the form code that is consuming ...
This code will load the MapInfo.Application object into a listbox and display the sample US County data. It assumes your form has a listbox called listBox1 and a "using System.Reflection;". It also works in Vista! string mapName = "C:\\Program Files\\MapInfo\\Professiona... System.Type oType = System.Type.GetTypeFromProg... object o = System.Activator.CreateInst... oType.InvokeMember("do... ...
If you want to install an application that is packaged as an .MSI and you want to know when the application has finished installing, use this code: string installerFilePath; installerFilePath = "C:\\Program Files\\CCS\\Downloads\\CCSR... System.Diagnostics.Process installerProcess; installerProcess = System.Diagnostics.Process.... "/q"); while (installerProcess.HasExited... { //indicate progress to user Application.DoEvents(); System.Threading.Thread.Sle... ...
I decided at HDC 2006 that it was time to make the switch from VB.net to C#. Not because it is better, but because all the presentations I go to are in C#. I hate having to convert languages in my head and since I give presentations every now and then, it's not fair to my audience to make them convert in their head. I've come to my first road block in migrating to C#. I really like the My. namespace that VB provides and C# doesn't have anything like it. I need to access the My.Computer.Network.IsAvail... ...