Archive

Archive for March, 2009

Cast<> to the rescue!

March 3rd, 2009 Nizar 2 comments

Just learn’t something today that I’d like to share.

Say you’ve got a generic list of

IQueryable<Person> persons;

that you’d like to convert to

IQueryable<IPerson> iPersons;

where Person : IPerson.

How do you do this? Very simple:

IQueryable<IPerson> iPersons = persons.Cast<IPerson>();

Note that:

IQueryable<IPerson> iPersons = (IQueryable<IPerson>)persons;

won’t work.

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Reddit Reddit Post to StumbleUpon

Fix to Mock.SetupAllProperties() – Not working in Moq 3.0

March 3rd, 2009 Nizar 1 comment

If you download the latest version of Moq, you’ll notice that the Mock.SetupAllProperties() method does not work. Try it in Debug mode and you’ll notice that the method just gets skipped.

Upon inspection, I discovered that a conditional attribute that was being applied to the method which was causing it to be skipped. I am assuming that attribute was meant to be removed but got overlooked.

Anyways, to fix it, here is what you do:

1. Download the source code for Moq and open up the file Mock.Generic.cs
2. Find the method SetupAllProperties() and remove the conditional attribute:
[Conditional("DESKTOP")]
3. Re-build and overwrite for existing Moq.dll that your project is referencing with the new one.

Cheers!

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Reddit Reddit Post to StumbleUpon

Bad Behavior has blocked 249 access attempts in the last 7 days.