"MVC" entries

Building C# objects dynamically

Using ExpandoObject to create objects that you can add properties, methods, and events to.

Buy “C# 6.0 Cookbook” in early release.
Editor’s note: This is an excerpt from “C# 6.0 Cookbook,” by Jay Hilyard and Stephen Teilhet. It offers more than 150 code recipes to common and not-so-common problems that C# programmers face every day. In it, you’ll find recipes on asynchronous methods, dynamic objects, enhanced error handling, the Rosyln compiler, and more.

Problem

You want to be able to build up an object to work with on the fly at runtime.

Solution

Use ExpandoObject to create an object that you can add properties, methods, and events to and be able to data bind to in a user interface.

We can use ExpandoObject to create an initial object to hold the Name and current Country of a person.

dynamic expando = new ExpandoObject();
expando.Name = "Brian";
expando.Country = "USA";

Once we have added properties directly, we can also add properties to our object in a more dynamic fashion using the AddProperty method we have provided for you. One example of why you might do this is to add properties to your object from another source of data. We will add the Language property.

Read more…

The Future of AngularJS

Charting the progress towards AngularJS 2.0

sextantAngularJS, for me, was a revelation the first time I encountered it. I was coming from using GWT (Google Web Toolkit), and seeing our large application shrink in lines of code by 90% was close to a spiritual experience. I was a convert from day one, because I knew how bad things were otherwise. Ever since, I have been associated with AngularJS in one way or another, and have seen how it makes things absolutely simple with data binding, templating, routing, unit testing, and so much more. But the more I used it, some things didn’t make sense, from naming to concepts. I got the hang of it, but I never really got to like why directives needed to be so complex, or how the built-in routing was quite limiting. While AngularJS made it trivial to write applications, it also made it trivial to write slow, hard-to-maintain applications if you didn’t understand how it all worked together.

Read more…