reflection

Patterns: Be independent of different subclasses by passing an Object array to the constructor

谁都会走 提交于 2020-01-07 07:42:09
问题 Let's say I load a whole lot of entities from a file. Most of these entities (Not all of them) are of a different class type, and thus may (Or may not) have a different constructor. However, all of them share one superclass: Entity.class How bad/good is it to let the superclass have one constructor public Entity(Object[] args); , so that the arguments will simply also be loaded from file and passed to the constructor, where the constructor then sorts out what exactly to do with that array?

OpenGL Environment mapping Reflection

此生再无相见时 提交于 2020-01-07 07:09:36
问题 my reflections are wrong. I have changed a lot of the code, but I didn't find the error. It would be great if you can help me. Texture generation: Code : m_cubeMap = new int[1]; m_cubeFB = new int[1]; // create the cube map glGenTextures ( 1, m_cubeMap, 0 ); glBindTexture ( GL_TEXTURE_CUBE_MAP, m_cubeMap[0] ); for( int i = 0; i < 6; i++ ) { glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, m_cubeMapSize, m_cubeMapSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, null ); } glTexParameteri( GL

How to make an external assembly available at runtime?

守給你的承諾、 提交于 2020-01-07 06:42:12
问题 I asked a question here and apparently the problem is where I can load an assembly using Reflection's Assembly.LoadFile or Assembly.LoadFrom , and get the type inside that assembly, the assembly is still not accessible in the whole application. So when WPF tries to resolve a type, it doesn't find that type because it doesn't find the assembly. My question is, can I reference an assembly at runtime, so that it will be resolvable by WPF? 回答1: A solution that works for me is handling the

Extend a generic class dynamically in Java

爱⌒轻易说出口 提交于 2020-01-07 05:34:31
问题 I need to extend on runtime a class with a generic signature. For example, the class to be extended is: public class A<T> {} I need to get this dynamically: public class B extends A<String> {} I cannot use Proxy because I need to add the obtained class to the ClassLoader. I'm trying with javassist but I have no idea of how make it in the correct way. 回答1: If you know type only at runtime, then you will have to use casting. Like: class TokenCounterMapper extends Mapper<Object, Object, Object,

Changing Class Variables in runtime?

若如初见. 提交于 2020-01-07 04:25:07
问题 Let me give an idea of what I wish to do: I have a structure or class called student , which contains variables like int roll_no and int reg_no If the user wishes to add a new variable like char name at run time how can it be done? 回答1: Based on the word "Structure" and the variable declarations, I'm going to guess this question is about some flavor of C. How exactly to do this will depend on the language, but as a general rule, if the language is compiled (e.g. C/C++, Java), this is not

Decompiled HtmlDocument's InvokeScript not working

 ̄綄美尐妖づ 提交于 2020-01-07 01:58:09
问题 Here is the code I got using ILSpy: public static object InvokeScript(this IHTMLDocument2 document, string scriptName, object[] args = null) { object result = null; UnsafeNativeMethods.tagDISPPARAMS tagDISPPARAMS = new UnsafeNativeMethods.tagDISPPARAMS(); tagDISPPARAMS.rgvarg = IntPtr.Zero; try { UnsafeNativeMethods.IDispatch dispatch = ((IHTMLDocument)document).Script as UnsafeNativeMethods.IDispatch; if (dispatch != null) { Guid empty = Guid.Empty; string[] rgszNames = new string[] {

How can identify Applet subclasses from a Jar file?

无人久伴 提交于 2020-01-06 22:44:19
问题 I have the two following class hierarchy in jar files where the only difference is that Main in example2.jar has no package while Main in example1.jar is part of the package user . example1.jar // user/Main.java package user; import Engine.GameWindow; public class Main extends GameWindow { } // Engine/GameWindow.java package Engine; import java.applet.Applet; public abstract class GameWindow extends Applet { } example2.jar // Main.java import Engine.GameWindow; public class Main extends

Plugin-system: How to handle events between host application and plugin

一曲冷凌霜 提交于 2020-01-06 19:52:20
问题 Note: I need to use .NET 3.5 My test application is in three parts (different projects and different dlls); host-application, plugin-sdk and test-plugin. The host application is a WPF application with an area to load in views from the plugins. Plugins is loaded through Reflection. This part work as supposed. The SDK contains common interfaces that a plugin can implement. One of my interfaces has an event that the plugin must implement and when it's triggered, the main application need to

Java reflection and interface as parameter

久未见 提交于 2020-01-06 19:32:38
问题 I'm trying to invoke a method via reflection. The method in question, let's say public void someMethod(someInterface<someObject> arg1) I do not have access to someMethod and someInterface at runtime, and have to invoke by someclass.getMethod("someMethod", new Class[]{Class.forName("someInterface")}) .invoke(...) But it fails with a ClassNotFound exception for someInterface . How do I get the Class object for interfaces? 回答1: I believe that you forgot the interface's package. You have to use

PlugIn function implementation with C#

心已入冬 提交于 2020-01-06 19:29:44
问题 I need to call a function to call user's dll in C#. For example, when user makes a abc.dll with class ABC, I want to load the dll to run the methods xyz(a) in the class. object plugInObject = node.GetPlugInObject("abc.dll", "ABC"); plugInObject.runMethod("xyz", "a"); How can I implement those functions in C#? ADDED This is plugin code, and the dll is copied as plugin/plugin.dll. namespace HIR { public class PlugIn { public int Add(int x, int y) { return (x + y); } } } This is the one that