TwitterFacebookGoogle

Cast<> to the rescue!

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.

Twitter Email Linkedin Digg Stumbleupon Subscribe

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

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!

Twitter Email Linkedin Digg Stumbleupon Subscribe
CyberChimps