Replies: 2 comments
-
Wow, I'm not sure how I didn't notice this message for two days. Sorry.
public abstract class Msg : IMsg<Counter> {
public Msg() { }
}
class Increment : Msg {
private static Increment _value = new Increment();
public static Increment Value { get { return _value; } }
private Increment() { }
...
}
class Decrement : Msg {
private static Decrement _value = new Decrement();
public static Decrement Value { get { return _value; } }
public Decrement() { }
...
} I typically write repetitive code using the "define" macro: public abstract class Msg : IMsg<Counter> {
public Msg() { }
}
define MakeSingletonClass($ClassName, $BaseClass, {$(..members);}) {
public class $ClassName : $BaseClass {
private static $ClassName _value = new $ClassName();
public static $ClassName Value { get { return _value; } }
private this() { } // constructor
$members;
}
}
MakeSingletonClass(Increment, Msg)
{
public void MethodOfIMsg() => Console.WriteLine("Incrementor!");
}
MakeSingletonClass(Decrement, Msg)
{
public void MethodOfIMsg() => Console.WriteLine("Decrementor!");
} A couple of notes:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for the answer, it helps. Macros are powerful, and easy to forget about it in C# world :) Btw, I more more see an examples of moving last argument out of a list to the make a kind of scope.. Kotlin recently. Good for DSLs. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a Messages and probably many more abstractions which a best represented as ADT here.
Btw, kudos for such an interesting project!
Beta Was this translation helpful? Give feedback.
All reactions