Archive for the ‘Uncategorized’ Category

Simplifying Rhino.Mocks; Round II

Monday, April 21st, 2008

Just a small idea before I go to work. As fol­low up to my yes­ter­days post about Rhino.Mocks. I fig­ured, that instead of sup­ply­ing arrays of object for con­struc­tor para­me­ters, which is error prone and doesn't give you the safety of com­piler checks, we can actu­ally insert the call to con­struc­tor using Expres­sions (notice that this is solu­tion that will work only in .NET >= 3.5).

Here's quick and dirty sketch of remade method:

public TTypeToMock Mock<TTypeToMock>(Kind mockKind, Expression<Func<TTypeToMock>> ctorCall, params Type[] extraTypes)
{
    if (extraTypes == null) throw new ArgumentNullException("extraTypes");
    if (ctorCall == null) throw new ArgumentNullException("ctorCall");
 
    if (mockKind == Kind.WithRemoting)
        mockKind &= Kind.Strict;
    else if (!_mockMethods.ContainsKey(mockKind))
    {
        if ((mockKind & Kind.WithRemoting) != 0)
            throw new ArgumentException("This kind of mock does not support remoting.");
        throw new ArgumentException("Invalid mock kind.", "mockKind");
    }
    var newCall = ctorCall.Body as NewExpression;
    if (newCall == null)
        throw new ArgumentException("Not a constructor call.", "ctorCall");
    var ctorArgs = new object[newCall.Arguments.Count];
    for (int i = 0; i < ctorArgs.Length; i++)
    {
        var param = newCall.Arguments[i] as ConstantExpression;
        if (param == null)
            throw new ArgumentException("You may only place constant values in calls to the constructor.");
        ctorArgs[i] = param.Value;
    }
    return CreateMock<TTypeToMock>(mockKind, extraTypes, ctorArgs);
}
 
private TTypeToMock CreateMock<TTypeToMock>(Kind mockKind, Type[] extraTypes, object[] ctorArgs)
{
    //NOTE: possibly with lock in this call
    var mock = (TTypeToMock) _mockMethods[mockKind](_repo, typeof (TTypeToMock), ctorArgs, extraTypes);
    return mock;
}

And with that you get in return this:

WindowClipping

Notice that you no longer need to spec­ify <MyClass> (it's grayed out) since com­piler can infer that from the Expression.

Tech­no­rati Tags: ,

Agile Toolkit Podcast

Wednesday, April 16th, 2008

I love read­ing blogs. I gain so much knowl­edge from peo­ple far smarter than myself. In my pre­vi­ous job it was tak­ing me about 40 min­utes to get there, and another 40 to return home. It's quite a lot I guess, wast­ing over an hour in pub­lic communication.

Then to make my com­mute a lit­tle bit more pro­duc­tive (ok, I lie here, it was just bor­ing) I decided to use my old Cre­ative Zen Micro mp3 player, and lis­ten to pod­casts. That's how it started, and now I have yet another source of knowl­edge about tech­nol­ogy, and what's great about it, is that I don't have to be in front of the com­puter, or even at home to use it. I'm hooked.

Any­way, when I ran out of Hanselmin­utes, Dot Net Rocks, Poly­mor­phic Pod­cast and Plumbers at Work episodes I started to look for some other great pod­casts out there and I just found out (via great XP group) about Agile Toolkit Pod­cast.

It seems to be the best agile-centric pod­cast around, and it's been pub­lished for roughly 3 years, so I have quite a few episodes to get up to speed with. At the moment I'm lis­ten­ing to an episode with James Shore, author of one of the books I bought last week. Great stuff, highly recommended.

Tech­no­rati Tags: , ,

Dr. Venkat Subramaniam on Agile Practices

Monday, March 31st, 2008

There's a great talk (video and slides) up on InfoQ, by Dr. Venkat Sub­ra­ma­niam on Agile Prac­tices. Be sure to check it out. Great stuff, great speaker, great author.

Tech­no­rati Tags: , ,

My favorite ReSharper' 4.0 feature

Thursday, February 21st, 2008

sshot-1Camel humps intel­lisense. Start using it, and you'll be won­der­ing how you could ever have lived with­out it.

 

 

 

Tech­no­rati Tags: , , ,

ReSharper 4.0 — at last

Friday, February 15th, 2008

rs4

Go get it here, and while you're down­load­ing, read release notes.

UPDATE:

And sud­denly I'm much less happy… :(

rs4_licence

UPDATE2:

Well, maybe not that much less happy ;)

Ilya Ryzhenkov said…

We will renew eval­u­a­tion period reg­u­lary, so all you need is use lat­est nightly build all the time ;)

Tech­no­rati Tags: ,

Visual Studio/ReSharper syntax coloring issue

Wednesday, January 23rd, 2008

I use cus­tom color theme in Visual Stu­dio. Black back­ground and light-colored fonts. After installing new ReSharper nightly build I noticed how­ever, that some­thing is not right. ReSharper adds addi­tional col­or­ing to your syn­tax, but it seemed to be dis­abled. I checked ReSharper's set­tings, and it looked OK. It turned out to be Visual Stu­dio issue. Looks like it didn't pick addi­tional col­ors from ReSharper. To fix this you need to open Tools –> Options, then nav­i­gate to Envi­ron­ment–> Fonts and Col­ors, and wait for Visual Stu­dio to reload its col­ors. You can close the win­dow now. All should be back to normal.

Before...After..

Framework tips III: DateTime.ToString() explained

Friday, January 18th, 2008

There seems to be much con­fu­sion around how DateTime's ToString method actu­ally works. Let me try to clear it out for you:

First, there are sev­eral ways of con­vert­ing Date­Time to String:

   1: public String ToLongDateString() {...}

   2: public String ToLongTimeString() {...}

   3: public String ToShortDateString() {...}

   4: public String ToShortTimeString() {...}

   5: public override String ToString() {...}

   6: public String ToString(String format) {...}

   7: public String ToString(IFormatProvider provider) {...}

   8: public String ToString(String format, IFormatProvider provider) {...}

Every of this meth­ods calls inter­nal method giv­ing it ref­er­ence to itself, for­mat string and Date­Time­For­mat­Info instance.

Call­ing meth­ods 1 — 7 is like call­ing method 8, with given parameters:

Method (and its parameters)

8th method's parameters

ToLong­Dat­eString() ("D", DateTimeFormatInfo.CurrentInfo)
ToLong­TimeString() ("T", DateTimeFormatInfo.CurrentInfo)
ToShort­Dat­eString() ("d", DateTimeFormatInfo.CurrentInfo)
ToShort­TimeString() ("t", DateTimeFormatInfo.CurrentInfo)
ToString() (null, DateTimeFormatInfo.CurrentInfo)
ToString(String for­mat) (for­mat, DateTimeFormatInfo.CurrentInfo)
ToString(IFormatProvider provider) (null, DateTimeFormatInfo.GetInstance(provider))

If you don't spec­ify IFor­mat­Provider, DateTimeFormatInfo.CurrentInfo is used, that is basically:

   1: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

So although you may be very spe­cific about your for­mat, Cur­rent cul­ture will be still take into account, which may result in unex­pected strings in some cul­tures. Notice that there are basi­cally three kinds of for­mat you may provide:

  1. null (or string.Empty)
  2. one-character long pre­de­fined format
  3. multi-character long cus­tom format

If you pro­vide null (or empty string), in almost every occa­sion this will result in Gen­eral date/long time for­mat­ting (same as pro­vid­ing "G" as format).

There is a list of all pre­de­fined for­mats here. Notice how­ever that for 'o', "O", "r", "R", "s" and "u", invari­ant Date­Time­For­mat­Info, will always be used. Next, pre­de­fined for­mat will be expanded accord­ing to given Date­Time­For­mat­Info' prop­er­ties (or their com­bi­na­tions), and ulti­mately, in all three above cases will end up with fully expanded for­mat­ting string, that will get trans­lated to date-time string accord­ing to rules spec­i­fied in sec­ond table on this site.

Notice how­ever that ':' and '/' have spe­cial mean­ing and are not treated like lit­er­als. If you do need to use them (or any other for­mat­ting char­ac­ter) as lit­eral, you have to pre­cede it with '\'. If you want to embed longer lit­eral string in the for­mat you have to put it within " or ' characters.

 

.NET Frame­work does its best to dis­play date and time accord­ing to user's set­tings, but if you need to make sure that date and time will always be dis­played the same way despite of user's set­tings, use the last over­load, and pass some Date­Time­For­mat­Info instace. Oth­er­wise, even if you use spe­cific for­mat strings like "yyyy-MM-dd HH:mm", you may end up with strings like: תשס"ח-ה'-י"א 10:06

Tech­no­rati Tags: , , ,

To continue installation close the installer

Saturday, December 8th, 2007

dotbetthreefiveinstaller The title says it all. I've unin­stalled beta2, and cur­rently I'm try­ing to install the final ver­sion of Visual Stu­dio 2008.

As many peo­ple had prob­lems with .NET 3.5 installer, while installing VS, I wanted to install it before installing Stu­dio. While installing it, I received one of the most bizarre noti­fi­ca­tions I've ever seen. Oh, and click­ing 'ignore' causes the installer to exit with an error. Any ideas?

Tech­no­rati Tags: ,

Go way back in time.

Tuesday, October 30th, 2007

I recently found this great web­site called Inter­net Archive:Wayback Machine. Basi­cally it lets you see snap­shots of dif­fer­ent web­sites start­ing from 1996 to present day. I found this fas­ci­nat­ing for at least two reasons.

  1. It's fun. To see how Microsoft's site looked back in 1996, or alpha ver­sion of Google.
  2. The other (more impor­tant aspect to me) is — this site is a great learn­ing tool. Like in movies you can go back in time and jump between eras, see how the world changed. How sites we visit every day looked like few years ago. It may be eye-opening, espe­cially for peo­ple design­ing web inter­faces. It's almost like arche­ol­ogy, it shows you how fash­ions changed, peo­ple went from dial-up to broad­band, and I must say — all web sites I looked at, look now bet­ter that any­where else in the past. I think it's a good sign, that despite of fash­ions, being all webt­woze­roish — usabil­ity improves.

 

Tech­no­rati Tags: , , ,

Of leave, flu, and irony

Monday, August 27th, 2007

I took a leave for two weeks, to enjoy this last days of sum­mer. Iron­i­cally it seems that I got a flu, I've a fever, and it seems that I'm going to enjoy it from my bed. Isn't it the leave one always dreams of?

Tech­no­rati Tags: