C#C
C#16mo ago
axo

null check raising errors

i come from python and my first interpretation was that they can work like decorators, but that's clearly not the case.

my question is how do i modify class data with an attribute?

like how in python you can decorate a class like this:
def change(name, value):
    def wrapper(cls):
        setattr(cls, name, value)
        return cls

    return wrapper

# ...

@change("num", 4)
class MyClass:
    def __init__(self):
        self.num = 10

mc = MyClass()
print(mc.num) # prints 4 and not 10


how would i do this in C#?
Was this page helpful?