Click here to Skip to main content
15,888,401 members
Home / Discussions / C#
   

C#

 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Pete O'Hanlon29-Jan-16 3:25
mvePete O'Hanlon29-Jan-16 3:25 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:47
mvaKenneth Haugland29-Jan-16 4:47 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Richard Deeming29-Jan-16 5:03
mveRichard Deeming29-Jan-16 5:03 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 5:22
mvaKenneth Haugland29-Jan-16 5:22 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Richard Deeming29-Jan-16 3:31
mveRichard Deeming29-Jan-16 3:31 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:56
mvaKenneth Haugland29-Jan-16 4:56 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Sascha Lefèvre29-Jan-16 3:49
professionalSascha Lefèvre29-Jan-16 3:49 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:59
mvaKenneth Haugland29-Jan-16 4:59 
Yes, working my way through the answers Big Grin | :-D

But I cant get your last line of code to compile, I had to do this:
C#
public static class ObservableEx
{
    public static IObservable<TResult> FromPropertyChanged<T, TResult>(T target, Expression<Func<T, TResult>> property)
    {
        Contract.Requires(target != null);
        Contract.Requires(property != null);

        var body = property.Body as MemberExpression;

        if (body == null)
            throw new ArgumentException("The specified expression does not reference a property.", "property");

        var propertyInfo = body.Member as PropertyInfo;

        if (propertyInfo == null)
            throw new ArgumentException("The specified expression does not reference a property.", "property");

        string propertyName = propertyInfo.Name;

        var propertyDescriptor = (from p in TypeDescriptor.GetProperties(target).Cast<PropertyDescriptor>()
                                  where string.Equals(p.Name, propertyName, StringComparison.Ordinal)
                                  select p)
              .Single();

        if (!propertyDescriptor.SupportsChangeEvents)
            throw new ArgumentException("The specified property does not support change events.", "property");

        var getter = property.Compile();

        return from e in Observable.FromEvent<EventHandler, EventArgs>(
            propertyChangedHandler => (s, e) => propertyChangedHandler(e),
          h => propertyDescriptor.AddValueChanged(target, h),
          h => propertyDescriptor.RemoveValueChanged(target, h))
               select getter(target);
    }
}

And the result will only return the actual value thats changed, not the sender and event args.
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Sascha Lefèvre29-Jan-16 5:30
professionalSascha Lefèvre29-Jan-16 5:30 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 5:51
mvaKenneth Haugland29-Jan-16 5:51 
QuestionEnable / Disable DNS Client service (c#) Pin
Member 1041097228-Jan-16 22:21
Member 1041097228-Jan-16 22:21 
AnswerRe: Enable / Disable DNS Client service (c#) Pin
Nathan Minier29-Jan-16 2:05
professionalNathan Minier29-Jan-16 2:05 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Member 1041097229-Jan-16 5:21
Member 1041097229-Jan-16 5:21 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Nathan Minier29-Jan-16 5:28
professionalNathan Minier29-Jan-16 5:28 
AnswerRe: Enable / Disable DNS Client service (c#) Pin
Eddy Vluggen29-Jan-16 2:19
professionalEddy Vluggen29-Jan-16 2:19 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Member 1041097229-Jan-16 5:25
Member 1041097229-Jan-16 5:25 
QuestionHow to change utc Date in a normal Date Pin
Member 1191673528-Jan-16 2:20
Member 1191673528-Jan-16 2:20 
AnswerRe: How to change utc Date in a normal Date Pin
Sascha Lefèvre28-Jan-16 3:06
professionalSascha Lefèvre28-Jan-16 3:06 
GeneralRe: How to change utc Date in a normal Date Pin
jschell29-Jan-16 12:26
jschell29-Jan-16 12:26 
AnswerRe: How to change utc Date in a normal Date Pin
Eddy Vluggen28-Jan-16 3:19
professionalEddy Vluggen28-Jan-16 3:19 
AnswerRe: How to change utc Date in a normal Date Pin
Midi_Mick28-Jan-16 14:00
professionalMidi_Mick28-Jan-16 14:00 
AnswerRe: How to change utc Date in a normal Date Pin
John Torjo28-Jan-16 19:54
professionalJohn Torjo28-Jan-16 19:54 
AnswerRe: How to change utc Date in a normal Date Pin
Member 1191673528-Jan-16 20:41
Member 1191673528-Jan-16 20:41 
GeneralRe: How to change utc Date in a normal Date Pin
Richard MacCutchan28-Jan-16 22:38
mveRichard MacCutchan28-Jan-16 22:38 
AnswerRe: How to change utc Date in a normal Date Pin
jschell29-Jan-16 12:23
jschell29-Jan-16 12:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.