Archive for May, 2008

Checking out the Source Analysis for C#

I’ve just spent about 30 minutes checking out the recently announced Microsoft Source Analysis for C#. I definitely love the idea, but I’m not sure I’ll be using it just yet. Here are some of my impressions (again, I haven’t spent a lot of time on it yet)…

All using directives must be placed inside of the namespace

Hmm, but VS itself violates that rule on every class we create…!


The property must not be placed on a single line. The opening and closing curly brackets must each be placed on their own line

Huh? But that an auto-implemented property. What would we want to split that into multiple lines?!


Variable names must not start with ‘m_’

Hmpf, that’s the standard with have here at the company…


A closing curly bracket must not be preceded by a blank line

Ok, this one I like.


Tabs are not allowed. Use spaces instead

Huh? Thanks, but no, thanks. I’ve seen a lot of people complaining online about this one too. What’s the problem with using tabs??


The call … must begin with ‘this.’…

Ah, I like that one. This is something we’ve made as part of our guideline here, but couldn’t use FxCop to trap for that, since the ‘this.’ doesn’t make into the IL.

Now, the problem here is that, again, the code that VS generates violates this rule all over the place, such as on the example below:


I’ll continue to use this tool to see if it’s going to stick with me. I’ve tried it on a very small project, and got 246 violations; the vast majority where produced by code generated by VS. On a big project, I’d probably end up with a LOT more violations, so I’m not sure I can live with that. I believe there is a way to disable some of the rules, but haven’t looked for it just yet…

Anyway, I do appreciate Microsoft releasing tools like this one. Hopefully, more and more developers will start paying more attention to how they write code.


Interesting training material

As an MVP, I got offered a license to InnerWorkings training material. I’ve been checking out some of it, and it looks pretty interesting.

I noticed they had some material on Domain-Driven Design Patterns, Enterprise Patterns, and some related topics that I’m always interested on, so I decided to try it out.

There is a "Developer Interface" app, where we keep all the material purchased. Each course has a number of tasks, and each task presents the scenario to be solved, the challenges, and reference material (with links to chapter of great books such as Eric Evan’s on Domain-Driven Design).


The task provides a way to launch the sample project in Visual Studio. Once in VS, we get an "InnerWorkings" Tool Window that gives us quick access to the problems we need to address in the solution, and the useful links.

You can either try to address the problems by yourself, or cheat and see the solution. Once you’re done with it, you may click the ‘Judge Project Code" button that gets added to VS to have your code analyzed to see if you’ve implemented things in the way that was expected.   

I’ll certainly be checking out some of the other courses they have available (I need to catch up with some stuff such as WCF, WPF, Silverlight, LINQ to XML, etc.).


Leave a comment

Getting rid of the slow help engine in Visual Studio

It’s been a few years already since the last time I’ve installed VS’ help (MSDN) on my machines. The thing is huge, slow to come up, and it didn’t use to be that good. I just got used to using a SlickRun magicword to quickly search google, which searches not only MSDN, but also other resources (often much better than MSDN) such as CodeProject, blogs, etc. Since I’m connected almost 100% of the time, why use the slow local MSDN library?

Also, every once in a while a reach for the F2 key in order to start a "rename" refactoring in Visual Studio, and and up pressing F1 by mistake, and then there go 2 minutes of my life, waiting for the help window to come up (even though, again, I don’t even have MSDN installed).

Talking to Mike today, I remembered I used to have a little VS macro that’d search on Google the text I have selected in VS. I thought it’d be good to just re-map the F1 key to that macro. It solves to problems: allows me to quickly perform a Google search from VS, and it doesn’t get me stuck waiting for the VS help window to come up if I’ve hit the F1 key by mistake.  🙂

You can find an example of such macro here. In order to change the keybinding, go to Tools-Options-Keyboard, search for the "GoogleSearch" macro, and bind the F1 key to it.


Leave a comment

Matching my own record: 5 and a half years at EPS!

Wow, today, May 16 2008, I’m matching my personal record at working with a company: 5 and a half years, or to be more precise, 2003 days.  🙂

Here’s a little history:

  • I’ve had my first full-time job when I was 12. It lasted only for a full week; I just couldn’t stand the boss.  🙂
  • When I was 14, I took a temporary job (also full-time), filling in for a friend for a full month.
  • The next Monday when I was done with the previous job, I was hired by a company across the hall: that was the company where I had stayed for 5 years and a half years. I started as a courier. After a year, I got promoted to a financial clerk (at the age of 15). Almost three years later, got promoted to a programmer/analyst.
  • From the previous job I went to a new company, as an IT guy (doing mostly software development, but also a lot of computer setup, networking, hardware, user support, etc.). I worked there for about 3 years.
  • Next, new company, now dedicated to software development. Worked there for about 14 months.
  • On to another company, where I’ve worked for about 8 or 9 months.

The reader have probably noticed the pattern: after the company where I’ve worked for over 5 years, my stay at every job was getting shorter and shorter.

Eventually I’ve decided to go solo as an independent consultant. I had my clients, I’ve put together some conferences for software developers, etc. That lasted for about 8 months. I wanted to have no strings attached to any company because at that time there was a good chance EPS would be hiring me, so I wanted to make sure I could join the company at any time. And that happened in November of 2002.

The rest, as they say, is history.  🙂

1 Comment

Material from Tulsa School of Dev 2008 is online

I’ve just uploaded the material I’ve presented last week at the Tulsa School of Dev 2008. The material includes slide decks and source code for my three sessions (C# 3.0, Design Patterns, and LINQ).

The material can be downloaded here.

Leave a comment

Attributes on constants? Haven’t thought about that…

I’m currently reading this article on CodeProject where the author is creating an MVP framework (seems like a good article so far…). In there, the author applies attributes to constants of a type. I had never thought that was actually possible. I want to make sure I keep that at the back of my mind, because I think I’ll be using it sometime soon.

As a quick reminder, this is how that can be implemented:

public class SomeClass
    [Special("Some special attribute")]
    public const string SomeConst = "This is some constant";

public class SpecialAttribute : Attribute
    public string Foo { get; set; }
    public SpecialAttribute(string foo)
        Foo = foo;

This blog post has a handy method to get a list of constants defined on a type (including its baseclasses):

/// This method will return all the constants from a particular
/// type including the constants from all the base types
/// </SUMMARY>
/// <PARAM NAME="TYPE">type to get the constants for</PARAM>
/// <RETURNS>array of FieldInfos for all the constants</RETURNS>
private FieldInfo[] GetConstants(System.Type type)
    ArrayList constants = new ArrayList();

    FieldInfo[] fieldInfos = type.GetFields(
        // Gets all public and static fields

        BindingFlags.Public | BindingFlags.Static |
        // This tells it to get the fields from all base types as well


    // Go through the list and only pick out the constants
    foreach (FieldInfo fi in fieldInfos)
        // IsLiteral determines if its value is written at 
        //   compile time and not changeable
        // IsInitOnly determine if the field can be set 
        //   in the body of the constructor
        // for C# a field which is readonly keyword would have both true 
        //   but a const field would have only IsLiteral equal to true
        if (fi.IsLiteral && !fi.IsInitOnly)

    // Return an array of FieldInfos
    return (FieldInfo[])constants.ToArray(typeof(FieldInfo));

And here’s a little test method to show how to get the attributes out of the constants of a type:

public void TestMethod1()
    SomeClass obj = new SomeClass();

    FieldInfo[] fields = GetConstants(obj.GetType());

    Assert.AreEqual(1, fields.Length);
    Assert.AreEqual("SomeConst", fields[0].Name);

    object[] attribs = fields[0].GetCustomAttributes(false);
    Assert.AreEqual(1, attribs.Length);

    SpecialAttribute special = attribs[0] as SpecialAttribute;
    Assert.AreEqual("Some special attribute", special.Foo);

Leave a comment

Vista gets on my nerves…

This is just stupid: I have a folder somewhere that I’ve created. It’s not under any security sensitive folder such as Program Files or Windows. I’ve copied some files into that folder. Then, I tried deleting the files. Vista asks me  typical security questions, and I say "yes, just delete the damn files". Eventually it just comes back to me and tells me "access is denied".

Then I try moving the files into a subfolder. It has no problems with that. Tried deleting the subfolder; no luck. Moved the files back to the original location.

Next, I try opening a Command Prompt, running it as admin. I tried deleting the files there, no success either.

Finally, I tried running Windows Explorer as admin, and voila, the stupid thing lets me delete the files that I HAVE CREATED!!! Oh joy. How hard should it be for me to delete a stupid file that I’ve created myself, sitting on a folder that I’ve also created, outside of any O.S. folder???

Leave a comment