.NET Introspection VS Reflection
What is the difference between Introspection and Reflection in .NET ...
What is the difference between Introspection and Reflection in .NET ...
So what I'm looking for here is something like PHP's print_r function. This is so I can debug my scripts by seeing what's the state of the object in question. ...
I have a dict, which I need to pass key/values as keyword arguments.. For example.. d_args = {'kw1': 'value1', 'kw2': 'value2'} example(**d_args) This works fine, but if there are values in the d_args dict that are not accepted by the example function, it obviously dies.. Say, if the example function is defined as def example(kw2): T...
I regularly want to check if an object has a member or not. An example is the creation of a singleton in a function. For that purpose, you can use hasattr like this: class Foo(object): @classmethod def singleton(self): if not hasattr(self, 'instance'): self.instance = Foo() return self.instance But ...
Given the python function: def aMethod(arg1, arg2): pass How can I extract the number and names of the arguments. Ie. given that I have a reference to func, I want the func.[something] to return ("arg1", "arg2") The usage scenario for this is that I have a decorator, and I wish to use the method arguments in the same order that t...
I'm new to ruby and I'm playing around with the irb. I found that I can list methods of an object using the ".methods" method, and that self.methods sort of gives me what I want (similar to python's dir(builtins)?), but how can I find the methods of a library/module I've loaded via include and require? irb(main):036:0* self.methods =>...
With common lisp and I am assuming the introspection properties. How can I add code to common lisp code that will tell me when a function is called and when has finished executing. I want to take any lisp code and this particular modification to the code. I figure with lisp's AST analysis, this should be possible. ...
Is there a (standardized) way to get the name of the current method using c++? Using GNU GCC you can do this by using the macro __FUNCTION__ and __PRETTY_FUNCTION__ (surrounded by 2 underscores), however, this is of course non portable. Is there a way to do this in standard c++ or a way to make it portable? ...
I know of is and as for instanceof, but what about the reflective isInstance() method? ...
What to do when after all probing, a reportedly valid object return 'undefined' for any attribute probed? I use jQuery, $('selector').mouseover(function() { }); Everything returns 'undefined' for $(this) inside the function scope. The selector is a 'area' for a map tag and I'm looking for its parent attributes. ...
I have set up a sort of introspection-enabling C++ library that allows, using minimum macros and a fair amount of template trickery, to declare structures and classes that get enriched with some meta-information. This meta-information captures all important details about each field of the struct/class that you declare, and at the end of...
I am trying to add the following method to the Math class in Ruby on Rails: class Math def self.round_with_precision(number, precision) scalar = 10.0 ** precision number = number * scalar number = number.round number = number / scalar return number; end end I then added the following to my environment.rb: requ...
I'm working on a test framework in Perl. As part of the tests, I may need to add precondition or postcondition checks for any given test, but not necessarily for all of them. What I've got so far is something like: eval "&verify_precondition_TEST$n"; print $@ if $@; Unfortunately, this outputs "Undefined subroutine &verify_preconditio...
In ruby, if I do "require foo", is there a way to subsequently determine the name of the module or modules defined in foo.rb? For example, say I have a ruby file named foo.rb that looks like this: # foo.rb module MyModule def self.summary "this does something useful" end ... end In another script, after I do "requ...
Given an instance of some class in Python, it would be useful to be able to determine which line of source code defined each method and property (e.g. to implement [1]). For example, given a module ab.py class A(object): z = 1 q = 2 def y(self): pass def x(self): pass class B(A): q = 4 def x(self): pass def ...
Why would a coder stuff things into __dict__ that can't be used for attribute access? For example, in my Plone instance, dir(portal) includes index_html, but portal.index_html raises AttributeError. This is also true for the __class__ attribute of Products.ZCatalog.Catalog.mybrains. Is there a good reason why dir() can't be trusted? Pok...
Hi, How do I find out a name of class that created an instance of an object in Python if the function I am doing this from is the base class of which the class of the instance has been derived? Was thinking maybe the inspects module might have helped me out here, but it doesn't seem to give me what I want and short of parsing the __cla...
I'm using Python 2.x and I have an object I'm summoning from the aether; the documentation on it is not particularly clear. I would like to be able to get a list of properties for that object and the type of each property. Similarly, I'd like to get a list of methods for that object, as well, plus any other information I could find o...
Say I have a variable named choice it is equal to 2. How would I access the name of the variable? Something equivalent to In [53]: namestr(choice) Out[53]: 'choice' for use in making a dictionary. There's a good way to do this and I'm just missing it. EDIT: The reason to do this is thus. I am running some data analysis stuff where I...
I'm writing a plugin system for my program and I can't get past one thing: class ThingLoader(object): ''' Loader class ''' def loadPlugins(self): ''' Get all the plugins from plugins folder ''' from diones.thingpad.plugin.IntrospectionHelper import loadClasses classList=loadClasses('./plugin...