Skip to content

Instantly share code, notes, and snippets.

@Pilchie
Forked from anaisbetts/gist:3486981
Created August 27, 2012 15:57
Show Gist options
  • Save Pilchie/3489783 to your computer and use it in GitHub Desktop.
Save Pilchie/3489783 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
var view = new MyView();
view.Bind/*<MyViewModel, MyView, int>*/(view.ViewModel, vm => vm.Prop1, v => v.Prop2);
}
}
class MyViewModel
{
public int Prop1 { get; set; }
}
class MyView : IViewFor<MyViewModel>
{
public int Prop2 { get; set; }
public MyViewModel ViewModel
{
get { return null; }
}
}
static class C
{
public static IDisposable Bind<TViewModel, TView, TProp>(
this TView view,
TViewModel vm,
Expression<Func<TViewModel, TProp>> vmProperty,
Expression<Func<TView, TProp>> viewProperty)
where TViewModel : class
where TView : IViewFor<TViewModel>
{
return null;
}
}
interface IViewFor<TViewModel>
{
TViewModel ViewModel { get; }
}
@Pilchie
Copy link
Author

Pilchie commented Aug 27, 2012

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var view = new MyView();
view.Bind/<MyViewModel, MyView, int>/(view.ViewModel, vm => vm.Prop1, v => v.Prop2);
}
}

class MyViewModel
{
    public int Prop1 { get; set; }
}

class MyView : IViewFor<MyViewModel>
{
    public int Prop2 { get; set; }

    public MyViewModel ViewModel
    {
        get { return null; }
    }
}

static class C
{
    public static IDisposable Bind<TViewModel, TView, TProp>(
            this TView view,
            TViewModel vm,
            Expression<Func<TViewModel, TProp>> vmProperty,
            Expression<Func<TView, TProp>> viewProperty)
        where TViewModel : class
        where TView : IViewFor<TViewModel>
    {
        return null;
    }
}

interface IViewFor<TViewModel>
{
    TViewModel ViewModel { get; }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment