What is the status of Python's __getattr __
in C #?
I have a class with many properties, and they all share the same accelerator code. I would like to be able to completely leave the personalized accessories in Python.
Here my code looks like:
class Foo {protected bool Get (string name, bauldef) {try {return client.Get (name); } Hold {return def; }} Public Butter Bar {get {return Get ("bar", true); } Set {client.Set ("bar", value); }} Public hair falcon {get {return Get ("baz", false); } Set {client.Set ("baz", value); }}}
and what I would like here:
square fu {public bool Get (string name) {try {return client.Get (name) ; } Hold {the default value to see in the hash table and return it}} Public Zero Set (string name, object value) {client.Set (name, value)}}
Anyone in C # without calling Although C # supports reflection, it is read only (for loaded assemblies) This means that you can not change any method, property or any other metadata Are there. However, you can call it, it will not be very convenient - it will be worse than the use of your Python does not see whether a feature exists at "compile-time" (or at least load-time). C # does have a basic difference between these two languages. In Python, you can do this: You will not be able to do this in C # because C # actually checks that name directly
get
method, a dictionary & lt; String, Object & gt;
And besides using an index for your class, you can not do that anyway, if you have many properties, then the dictionary is not doing better?
my_attr
is present at the time of compilation.
Comments
Post a Comment