reflection

Scrolling DataGridView per pixel

微笑、不失礼 提交于 2019-12-31 05:46:05
问题 I am making a .NET 4 WinForms application which reads data from a database and displays rows in a DGV. However the number of rows is larger than maximum number of rows that can fit on screen at once. To display all data, I need to scroll the DGV automatically until the last row and update the data source after that in order to refresh the DGV. I found it's easy to do that by simply incrementing FirstDisplayedScrollingRowIndex by one. However the scrolling is too sharp. I would like it to

Calling a function or method by reflection in C/C++

眉间皱痕 提交于 2019-12-31 05:43:07
问题 I am just going through a problem that I haven't before in C/C++, and I have no idea how to solve it. Reflection. I need to call a function or method by a string that was given by the user. Not just this, I also need to give the function or method some parameters and get its result if any. Imagine the user has typed printSomething . I need to evaluate "printSomething"(paramA, paramB) . Of course, the function or method T printSomething() is defined. How is the best way I can do it? 回答1: Use a

Implement a Properties Filter in .NET

▼魔方 西西 提交于 2019-12-31 05:30:08
问题 I have to filter a list of objects. The filter should be composed by users using logical OR / AND operators, and grouping using brackets. say, something like this: Say, we have object MyObj and its properties Prop1, Prop2, Prop3 Having myObjList the user could filter elements that Prop1 == aValue AND Prop2 < otherValue OR Prop2 > thirdvalue Is there some known (reflection) mechanisms that permits to manage this kind of filtering operations? 回答1: You can use dynamic linq to construct filter

Reflection - Iterate object's properties recursively within my own assemblies (Vb.Net/3.5)

喜你入骨 提交于 2019-12-31 05:23:06
问题 I wonder if anyone can help me - I've not done much with reflection but understand the basic principles. What I'm trying to do: I'm in the process of developing a class that gathers a lot of information about the local system, network, etc... to be used for automated bug reporting. Instead of having to change my test harness every time I add a new property, I'd (ideally) like to be able to serialise the lot as an XML string and just display that in a textbox. Unfortunately, the Framework won

Accessing a class member variable by its name at runtime [duplicate]

此生再无相见时 提交于 2019-12-31 05:19:10
问题 This question already has answers here : Get attribute by name (5 answers) Closed 12 months ago . In the vein of more impossible-but-is-it-really questions: Is it possible to access the member variable of a class, where the variable's name is stored in a string? class Test { public: int test = 0; } string name = "test"; // let's assume we know test is an int. Any chance of getting the value of test, using the string? One bit of cheating not allowed: enum vartype { INT, .. } No forcing the

Get the defining class for a constant in PHP

ぐ巨炮叔叔 提交于 2019-12-31 04:10:53
问题 I am wanting to use reflection to obtain a list of the constants defined by a class in PHP. Currently using reflection I can get a list of the constants, but this also includes the ones declared in inherited classes. Is there a method I can use to either; Given a class, get the constants defined by that class only Given a constant and a class, check if that constant was defined by that class (not an inherited or extended parent). For example, in the following code: class Foo { const PARENT

Java Reflection. Running a external jar and referring to its classes?

久未见 提交于 2019-12-31 03:59:37
问题 This code snippet allows me to run a jar as part of my program: File f = new File("client.jar"); URLClassLoader cl = new URLClassLoader(new URL[]{f.toURI().toURL(), null}); Class<?> clazz = cl.loadClass("epicurus.Client"); Method main = clazz.getMethod("main", String[].class); main.invoke(null, new Object[]{new String[]{}}); Is there anyway that I can refer to that external program's classes? I want to be able to change the title of its JFrame for instance. 回答1: I believe you could. I'd

Reflection: get invocation object in static method

狂风中的少年 提交于 2019-12-31 03:53:28
问题 Is it possible to get an object that invoked static method in this method? I have this code: class A{ static void foo(){ } } A a = new A(); a.foo(); Can I get instance a in method foo() ? 回答1: Firstly, your code isn't good as a programmer. It is because static methods are class-level methods and should be called without any instance of class. Recommended approach : class A{ static void foo(){ } } A.foo(); Can I get instance a in method foo() ? Nope, you can't. Because foo() is declared as

Retrieving parameter values through reflection

巧了我就是萌 提交于 2019-12-31 03:38:06
问题 I am trying to come up with a design for a method that takes another method as a parameter and retrieves the parameter values of the method passed. How can this be done? I've tried using java.lang.reflect.* but can't seem to find an API that supports this. 回答1: You can't really get the values passed as parameters like this. You can make your own Proxy and from there capture parameters before calling the right method. Or with aspect you could get the parameters value directly when the method

__invoke() on callable Array or String

ε祈祈猫儿з 提交于 2019-12-31 03:17:07
问题 How would one write PHP code to call all "Callables" with __invoke() ? The desire here is pass by reference, which is deprecated with call_user_func[_array]() . I did see that there is a package out there, TRex\Reflection\CallableReflection , but this seems to utilize call_user_func() in the background, and would suffer the same issue. <?php function passthrough_invoke(callable $callback) { return $callback->__invoke(); } function passthrough_user(callable $callback) { return call_user_func(