There are a number of places in our code where () => {} is used (required Action parameter in methods of third-party library).
To make code cleaner I created the following class:
public static class Empty
{
public static readonly Action Action = () => {};
}
Now it is much nicer:
Alert.Show(title, message, Empty.Action);
The question is may this refactoring cause any problems? I'm sure no but you may know possible side cases. Or may be you know better code improvement here?
This change is technically observable: there is always the possibility that some code indirectly compares two new Action(() => {}) instances for equality, and where they would previously not compare equal, they do now.
For an example, if you expose an public event Action X;, you might make sure to initialise it to () => {} to make sure it's never null, and remove any null checks from your code. If you change this to Empty.Action, then malicious code could write X -= Empty.Action;, causing a NullReferenceException in your own code where the event gets invoked.
But in well-written code, the refactoring should not make any difference.
This will not cause any problems, as it is equivalent to defining a static method and referencing it multiple times in your assembly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With