Is planed support of decorators? #72
Replies: 3 comments 1 reply
-
I created a sample that shows how you can invoke another target, which could be used for something like this. The tricky part about this is that for a simple case like the one you show above it's simple. But what if the type you're decorating is also the base class? What if some members are virtual but not others? What if you specified multiple interfaces? Maybe decorating is only enabled for interfaces? I think instead of a decorator interface and setter, it might be simpler to just generate a ctor receiving the interface(s) as targets, and modify the generated code to invoke that if non-null at the call-site, like: public int Add(int x, int y) => pipeline.Execute<int>(MethodInvocation.Create(this, MethodBase.GetCurrentMethod(),
calculator != null
? (m, n) => m.CreateValueReturn(base.Add(x, y), m.Arguments)
: (m, n) => throw new NotImplementedException(),
x, y)); |
Beta Was this translation helpful? Give feedback.
-
Dynamic call methods are of the order of magnitude slower.
Understand. That's why I only allowed interface decoration in my library. I mean is it cleaner.
Yes, I agree. (Maybe it will extend to classes in the future, if SourceGeneraors have a stronger API.)
I think that may be the case. |
Beta Was this translation helpful? Give feedback.
-
I'd be happy to help. |
Beta Was this translation helpful? Give feedback.
-
Is planed support of Decorator pattern with compile time generation for hig performace scenarios?
Eg:
See also API in my implementation of runtime decorator decorator https://github.com/harrison314/MassiveDynamicProxyGenerator#generate-decorator.
Beta Was this translation helpful? Give feedback.
All reactions