Search This Blog

Thursday, October 25, 2012

Specially for two guys from DevCon'12 with whom we chatted a lot about XAF

Here you go:

public abstract class ObjectViewController<ViewType, ObjectType> : 
        ViewController<ViewType> where ViewType : ObjectView {
        public ObjectViewController()
            : base() {
            this.TargetObjectType = typeof(ObjectType);
        public ObjectType ViewCurrentObject {
            get { return (ObjectType)View.CurrentObject; }


For people who do not quite understand what is going on, this is a new short way of declaring a ViewController in code to target it for a certain business object and View type at the same time.

So, starting with 12.1, you can write the following code:

    public class MyCoolViewController : ObjectViewController<DetailView, Contact> {
        protected override void OnActivated() {
            Contact theContact = ViewCurrentObject;

Enjoy! And generics rock!

No comments:

Post a Comment