question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to have a get/set property invoke a side-effect on a call to set and still persist the supplied value

See original GitHub issue

From @DanielRose’s comment in #962

Possibly giving the example that he and @thomaslevesque collaborated on would be best:

A.CallToSet(() => foo.Bar).Invokes((int bar) =>
{
    A.CallTo(() => foo.Bar).Returns(bar);
    foo.BarChanged += Raise.With(foo, EventsArgs.Empty);
});

although maybe with some cutesy candy shoppe jargon. Or a lovesick robot.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blairconradcommented, Jul 8, 2020

Thanks for the ides, @DanielRose. I appreciate the effort you’ve put into looking through the documentation for likely points to add the new information. Some thoughts:

Add the “default” code to Default fake behavior for reference, i.e.

I’d rather not insert code at this point. I think the text here now does convey the default behaviour better than the code would, but if it’s still not clear enough, I’d like to explore non-code ways to explain it first, at least.

  • Document an example (as above) in Property Setter and maybe also in Invoking Custom Code?
  • Or mention that using such a configuration will override the default behaviour, and have a link to the default behaviour. In that case also include a custom example

The Specifying a call to a property setter section’s focus is more on how to specify which call to override, than actually overriding the code, so I’m again not super excited about putting the sample code in here. A reminder that actually configuring the setter will break the magic get/set relationship, with a pointer to your sample below, sounds like a good idea. The same kind of note could also be added to the Default fake behavior article.

A.CallToSet(() => foo.Bar).Invokes((int bar) =>
{
    foo.BarChanging += Raise.With(foo, EventsArgs.Empty); // foo.Bar returns the old value
    A.CallTo(() => foo.Bar).Returns(bar);
    foo.BarChanged += Raise.With(foo, EventsArgs.Empty); // foo.Bar returns the new value
});

I love this example, despite the lack of lovesick robots. As I sit here, my favourite course of action would be to add it as a “Case study” kind of thing on Invoking Custom Code, which, if I understood you right, was a suggestion you made above.

0reactions
blairconradcommented, Jul 23, 2020

Thanks, @DanielRose . Look for your name in the release notes! 🥇

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Why is it impossible to override a getter-only property ...
This enables us to override properties with get / set even if they lacked a setter in their base definition. Situation: Pre-existing get...
Read more >
Property getters and setters
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >
Getters and Setters: Manage Attributes in Python
Typically, getter methods return the target attribute's value, while setter methods take a new value and assign it to the underlying attribute.
Read more >
A complete guide to the useEffect React Hook
With useEffect , you invoke side effects from within functional components, which is an important concept to understand in the React Hooks era....
Read more >
Custom dependency properties - UWP applications
Explains how to define and implement custom dependency properties for a Windows Runtime app using C++, C#, or Visual Basic.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found