Repository navigation
Replies: 5 comments 30 replies
Do: var info = new ProcessStartInfo();
if (workingDirectory != null) info.WorkingDirectory = workingDirectory; |
This is already legal code. But not really sensible. since |
I don't really get what this is trying to do. |
|
In case of
Yes. Process.Start(path, info ? info : default);
class ProcessStartAndMoreInfo : ProcessStartInfoThis is impossible because For the general question (disallow setting a property), there are many cases:
The last "solution" has the side effect of disallowing further overrides in case the property is var d = new D();
// d.Prop = 1;
((B)d).Prop = 1;
public class B
{
public int Prop { get; set; }
}
public class D : B
{
public new void Prop() { }
} |
|
After further thinking about this, this is actually what monads in functional programming can do. Right? Though using only fmap from Functor, no Applicative functionality, but Monad to allowed for side effects, even though in actual Haskell there is no assignment monad (as far as I know), so In Haskell-like psuedo code: |
Uh oh!
There was an error while loading. Please reload this page.
I tried searching the discussions, but I don't have time to go through 10 pages of them. So if this is a duplicate, well, that is just how it is.
I was wondering if there is a way to do something like this:
That doesn't seem like a helpful way to implement this, as that would make this functionality unusable in property accessors.
The keyword
defaultI assume always uses the default for the type, not the default value in a signature of a type or function (overload)?So for example like this, keeping the default value of the signature, not the type's default constructor:
Something like this for example, was also a way of solving what I was trying to solve (making specific properties inaccessible to avoid confusion due to accidental duplication, as above with
workingDirectory):In C++ (20 or later), this can be done using a template constraint I expect?
Any way to solve this problem in C#?
All reactions