Hadi Hariri

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

Dynamic objects and ReSharper

 

As you might have heard by now, C# 4.0 (or is it just 4?…) comes with a new keyword: dynamic. This means that you could do something like the following:

image

Simply put, ExpandoObject is a class that allows you to add and remove members at runtime. This allows us to call methods that are resolved at runtime. As such, the previous code will compile.

Just as you can declare methods, you can also declare properties:

image

This no doubt can come in handy when working with ViewModels and ASP.NET MVC.

However, there is one minor problem with dynamic objects: you lose intellisense, which means that if in your view, instead of typing dynaCustomer.FirstName, you type dynaCustomer.FristName, you won’t get any errors until you run the app.

image

And that’s where ReSharper can help:

image

This is the same code, but with ReSharper activated inside Visual Studio 2010! I typed the FirstName property for the first time. After that, I have full intellisense support for it. The same would apply to methods:

image

That puts dynamic into perspective.


Posted 11-24-2009 8:41 PM by Hadi Hariri
Filed under:

[Advertisement]

Comments

Bob wrote re: Dynamic objects and ReSharper
on 11-24-2009 4:10 PM

"However, there is one minor problem with dynamic objects: you loose intellisense, ..."

The word is lose, not loose.

Hadi Hariri wrote re: Dynamic objects and ReSharper
on 11-24-2009 4:22 PM

@Bob,

Sorry about that. You're absolutely correct. It was a typo. Corrected, thanks.

Rob Reynolds wrote re: Dynamic objects and ReSharper
on 11-25-2009 8:56 AM

Now that is a bonus! As always, the folks at Jetbrains continue to impress.

Pat Gannon wrote re: Dynamic objects and ReSharper
on 11-25-2009 6:34 PM

That is really cool stuff!  If only they could somehow integrate with IronRuby, and show all of the methods available on dynamic objects being returned from IronRuby invocations.  (Drooling at the possibility...)

Stefan wrote re: Dynamic objects and ReSharper
on 11-26-2009 2:12 AM

This isn't all that new, VS has done this with JS for ages, and while it could be better, it works alright, but is annoyingly wrong pretty often too.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)

CodeBetter.Com