Created
January 12, 2012 23:28
-
-
Save Porges/1603793 to your computer and use it in GitHub Desktop.
Repro for StackOverflow #8609110
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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