Skip to content

Instantly share code, notes, and snippets.

@Porges
Created January 12, 2012 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Porges/1603793 to your computer and use it in GitHub Desktop.
Save Porges/1603793 to your computer and use it in GitHub Desktop.
Repro for StackOverflow #8609110
using System;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Linq.Expressions;
namespace ConsoleApplication
{
class MyViewModel : INotifyPropertyChanged
{
public object Value { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class Program
{
public static void Main()
{
var OnValueChanged = new Action<MyViewModel>(x => { });
var myObserver = new PropertyObserver<MyViewModel>();
//this line throws the error, within the n => n.Value expression
myObserver.RegisterHandler(n => n.Value, OnValueChanged);
}
}
public class PropertyObserver<TPropertySource> where TPropertySource : INotifyPropertyChanged
{
public PropertyObserver<TPropertySource> RegisterHandler(Expression<Func<TPropertySource, object>> expression, Action<TPropertySource> handler)
{
Contract.Requires(expression != null);
Contract.Requires(handler != null);
throw new NotImplementedException();
//what this does is irrelevant; the violation occurs in the method call
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment