β Use `this` inside method decorator
Tried to follow https://stackoverflow.com/a/2966758
Can't figure out how to access
this
using method decoratorStack Overflow
Can I use the decorator pattern to wrap a method body?
I have a bunch of methods with varying signatures. These methods interact with a fragile data connection, so we often use a helper class to perform retries/reconnects, etc. Like so:
MyHelper.
V
viβ’415d ago
side note I was like "how hard can it be I will just factor out the simple side effect code into a decorator and have it up front"
oh how naive
@nekodjin ^u^
S
sampersandβ’415d ago
lol
V
viβ’415d ago
oh damn you too huh
yeah I actually thought decorators of all thing would be a small cost abstraction to make my code a little prettier
I'm f*cking stupid
sigh
but alas, I still want my pretty
[Effect]
boxes so, here we areN
nekodjinβ’415d ago
C# doesn't have decorators
A
Angiusβ’415d ago
Attributes are just metadata
For some other code to find and do something with
They're not like C++ macros or anything of the sort
V
viβ’415d ago
but you can sandwich the original method in extra stuffs right?
N
nekodjinβ’415d ago
no..
if so it'd be a decorator :p
A
Angiusβ’415d ago
Only in a very roundabout way. The attribute can contain a
Pre
and Post
methods, then you can get a method with this attribute using reflections, and execute Pre()
then ActualMethod()
then Post()
Attributes themselves don't ever execute
Something has to execute themN
nekodjinβ’415d ago
A
Angiusβ’415d ago
You can, of course, do something like
and call it with
V
viβ’415d ago
mmm
I did an inefficient but it makes my brain happy
N
nekodjinβ’415d ago
the long and short of it, vi, is give up the decorator idea
if i know anything about what you might be trying to use it for lol
V
viβ’415d ago
>.<
V
viβ’415d ago
yeah, sigh no actually interesting decorators
A
Angiusβ’415d ago
https://github.com/Fody/MethodDecorator shenanigans with Fody are an option if you really want decorators
N
nekodjinβ’415d ago
oh no..
don't encourage her π
she'll end up trying to make monads with a do notation decorator or smth
V
viβ’415d ago
o.o
OwO
algebraic effects in C#?
>.>
N
nekodjinβ’415d ago
aaaaaaaaaaaaa
V
viβ’415d ago
listen
I autismo
N
nekodjinβ’415d ago
sigh
V
viβ’415d ago
FP go brr
A
Accordβ’414d ago
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
52KMembers
View on DiscordWant results from more Discord servers?
More Postsβ
How can I make VSCode auto add semicolons to statements on save?I'm coming from the world of Javascript and Typescript. There, you can just use Prettier to automatiβ Find common substring at start of every string in listI have a list of Windows path strings and I want to determine the common beginning shared by all of β Code is completely skipping over an areaI'm writing a script for a game where if you don't press Spacebar within 4 seconds, the number of faβ Registering an extracted appx package```csharp
public static void RegisterMinecraftAppxPackage(string appxPackagePath) {
try {
β
Exception Handling for NRE without modifying every call.I have a ReadData function which reads the memory of a process. If the process exits or crashes duriβ
please help idk what to do or what i didSeverity Code Description Project File Line Suppression State
Error Projectβ Better user experience inputting commandsHow would I get input from a user, the fancy way?
What I mean is that for example when a user types β Return in the middle of a methodIs it ok?
I think that it improves readability and performance, but a professor I know argues that iβ Can't build a MSIX Package for a WPF appβ Should photo urls be sent paginated to the frontend?So, any given property has a collection of photos in a photo album... they are saved as urls in the β c# wpf textbox access violationHello does anyone know how can i edit the TextBox1.Text within the Task.run so i don't have an accesβ Help with choosing between ArrayList and other types of collectionsI was challenged to make a pokΓ©mon styled game without using classes and I wanted to know better wayβ How can you create a string that creates random characters?Title ^
(Console application)β β
abstract-Parent and Child static overrides?How do I redeclare an objects element which needs be from a static context in a child class?
I haveβ Asking if someone wants to be part of my project (Valorant Discord Rich Presence)Heyheyhey
Does some people here play Valorant and want to help me create a Discord Rich Presence usiβ asp.net web app debug in vscodelI am trying to find out what the database is returning for a specific variable on one of my view paβ <AuthorizeView> not workingI am currently making a Blazor Server App with a Custom Authentication. I can give my current user rβ β
Update Dropdown options in Unity without loosing selected optionI have written a StatSelector class. The purpose is to let the user assign generated values to his cβ How can I store history of each tree node in memory without any leaks?```cpp
public class TreeNode
{
protected TreeNode(string part) : this(part, -1, null) {}
β β
Lifetime of variable referenced in Func<>In some of my tests, I'm creating tables as I go, and then dropping the tables at the end of the tes