November Happy Hour will be moved to Thursday December 5th.

mnord
Oct 29, 2008
  5637
(0 votes)

Using dynamic languages with EPiServer Community

So I'm at MS PDC in Los Angeles and yesterday I attended the session on the DLR (Dynamic Language Runtime) which got me thinking on its possibilities in the EPiServer Community framework. Dynamic languages have been around for quite some time, and those who are familiar with a dynamic language know the benefits, and the confusion involved. With a static language you know what you're getting, you know the properties that are part of your object and you know the type they expose.

If you at any time could change the existence of a property or change its type, life becomes confusing. But when you develop a product these days nothing that you deliver to your customers will ever fit perfectly into what they want - hence the Community attribute system (or properties in CMS) was developed. The community attribute system lets us dynamically specify the blueprint of an object but it also gives us some control because we can strongly type each one of our attributes. When we are using a static and predictable language like C# this works well - we can be sure of the type, but still they do not become part of the object in the same way as developers are used to with the statically created properties.

.NET 4.0 will introduce dynamic possibilities in C# by the static type "dynamic". The "dynamic" type will allow you to treat objects that are inheriting DynamicObject with a lot less constraints than you are used to and you could write something like this:

public class Company : DynamicObject
{
// implementation
}

...

dynamic d = new Company();
d.Founded = DateTime.Now;

but it also allows something as horrible as this:

d.Founded = "yesterday";

So how do we get the best out of both worlds? We want to dynamically create new properties on an object, but we would want some kind of type control. Luckily the whole process for implementing a DynamicObject is up to the implementor and the implementation is very similar to the attribute system (basically a collection of name-value pairs). If we would apply the same type control as we have today onto the implementation of DynamicObject, we would get a semi-dynamic object that would result in a far better scenario:

dynamic d = new Company();
d.Founded = DateTime.Now;
d.Founded = "yesterday"; // will throw since the definition expects the type DateTime

Sure, having gotten a compile error before this would have been ideal, but this is the result of merging static with dynamic.

Oct 29, 2008

Comments

Sep 21, 2010 10:32 AM

Nice post!
/ Paul Smith

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog