Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [reflection]

Reflection is the ability of a computer program to examine, introspect, and modify its own structure and behavior at runtime.

4
votes
1answer
155 views

Alternative to Reflection

I will directly come to our current working flow so that you can understand the problem in a clear picture. I am attached in Laboratory Automation System in which Analyzer (a machine that performs ...
2
votes
3answers
99 views

How to build rest calls dynamically to interface with different APIs?

Lets say I am building an application where clients can book bus tickets. The only thing they do is select, origin, destination and the type of service (express or standard). The system will then book ...
0
votes
1answer
74 views

Method for loading and running user defined code in .NET windows application

Are there any patterns that address how to have and application load and run user defined code at run-time? I am looking into developing a C# library that the users of a Test Executive application (...
2
votes
3answers
165 views

Is there a pattern to describe a class that symbolises an instance of an instance of another class?

I am currently working on a project that generates videos from templates (a template being a collection of JSON files and assets). It seems natural to have a Template class that contains all the info ...
0
votes
1answer
68 views

Effective ways of dealing with static analyser warnings caused by incidental use of reflection

I don't normally use reflection directly while programming in Java. But I do use APIs and frameworks that internally rely on reflection or annotations to provide customization points. A lot of ...
1
vote
1answer
181 views

Need to call private method in third party library. Copy all class or use reflection?

I need to call a method that is available in a third party library, but it is a private method. There is no direct or indirect way to obtain the same functionality via public methods available. I ...
1
vote
1answer
67 views

Is there a simple way to call a method on an object in another program with a given id over TCP?

I'm working on a project where I have two programs which need to invoke methods on some of each other's objects. I do this by sending JSON objects over a TCP connection. These objects have a ...
4
votes
3answers
383 views

PHP: Is variable variables syntax an example of reflection?

I got into a conversation with a coworker and we talked about reflection in PHP language. I insisted that instantiating instances of class using variable variables syntax like following is a ...
8
votes
2answers
1k views

How to design a C++ program to allow for runtime import of functions?

today, I like to ask you a question towards the capabilities of C++ to realize a specific software architecture. Of course, I have used the search but have not found any directly linked answer. ...
47
votes
4answers
11k views

Why is it a bad idea to create a generic setter and getter with reflection?

A while back I wrote this answer to a question on how to avoid having a getter and setter for every mutable variable. At the time, I had only a hard-to-verbalize gut feeling that this is a Bad Idea, ...
1
vote
2answers
77 views

Why 'Package' type does not inherit 'AccessibleObject' type?

Below are the relevant types(in java) for annotation processing, In addition to Field & Method types, Package type is also used in context of annotations with reflection, because these types ...
0
votes
1answer
252 views

Is using Java reflection to map frontend actions to the actual db methods by name bad practice?

I have used java reflection with a static map to map actions(removeElements, getLatest ...) from the front end to the corresponding database methods by name in multiple web applications now. I was ...
0
votes
2answers
2k views

Annotation to define values for method argument

In a project, I have a task scheduling service, which is allowed to execute certain public methods from other services. Each service decides itself, which methods it want to make available for the ...
5
votes
6answers
576 views

In creating a “registry”, which is worse: using reflection or violating open/closed principle?

In my current software engineering course, my team is working on a library management system that is essentially a command-line/REPL environment with a half dozen commands, e.g. checkout, search, etc. ...
8
votes
4answers
3k views

Best practice to mark a method that is called via reflection?

Our software has several classes that should be dynamically found via reflection. The classes all have a constructor with a specific signature via which the reflection code instantiates objects. ...
0
votes
1answer
61 views

Auto-generated Api help pages test dialog using parameter options from a data service

I am a student worker currently close to the finish line of a project I have been working on. Right now I'm implementing the .net Auto generated Api help pages. The nuget package WebApiTestClient does ...
2
votes
1answer
1k views

Serialize Entity Framework Objects Without Lazy Loading

I have a very specific scenario that I'm not sure is possible to fully support: I have an ASP.NET application that uses Entity Framework 6.3 for it's data management. I also have a generic audit ...
0
votes
2answers
215 views

Introspection vs polymorphism in C#

I'm wondering how costly C# introspection really is in terms of class type inspection. Let's say I have a problem, where in a method of D I have to decide to take an action depending on the type of ...
14
votes
6answers
5k views

Is Reflection a disadvantage as private variables cannot be restricted?

The private modifier is used to restrict access outside the class, but using reflection other classes can access private method and fields. So I am wondering how we can restrict accessibility if it ...
0
votes
2answers
925 views

Set data in multi-level objects (may be using Java Reflection)

I want to possibly use Java Reflection to set some data at RunTime. My problem is I can't figure out how do I get sub-classes information and use as a part of reflection. I want to use Reflection to ...
1
vote
2answers
211 views

Finding types in TypeScript

I'm using a lot of implicit any in TypeScript. I don't quite understand how to decipher a TSD file in order to get the correct type when building off a library like express or angular. Is there a way ...
3
votes
3answers
2k views

Child class accessing its parent's method from Ancestor method

I find myself right now banging my head with the following issue (in PHP): I have an abstract base class, which has a non-abstract method, inherited and unchanged all over the inheritance chain (...
0
votes
0answers
163 views

Integrating legacy application with new functionality

We have a legacy application with, among other things, the ability to create instances classes within VB6 DLLs dynamically and call methods with varying signatures. We have no way of accessing the ...
1
vote
1answer
691 views

How can I make an object/class inaccessible to Reflection

I am building an API for minecraft called the Quantum API. We all know that reflection can be used to do some nasty stuff to classes, and even cause undefined behavior if used without care. Is there ...
0
votes
1answer
117 views

Reflection performance in this iteration of a (probably) large excel file

I'm wondering the performance of reflection in this situation. I'm iterating a (probably) large excel file (let's say 3000 max) which it's going to be done from time to time, and the implementation ...
3
votes
2answers
648 views

C# static practices coming from dynamic background

I have been dappling in C# after coming from several years in PHP. I don't find the language particularly difficult, although there are considerably more constructs for me to get used to. My question ...
3
votes
2answers
589 views

Using reflection vs creating a new class

I and a friend are having an argument on what is the better technique to use in the following scenario: An application we need to test has a number of components (lets call them Eggs); each component ...
3
votes
1answer
785 views

Debugging xml and annotations

By now, most web containers have an annotation variant of their xml configurations for Java EE. I'm guessing this is because it's better to keep things in Java where they can be managed, coded with ...
1
vote
1answer
3k views

assembly.GetTypes() vs assembly.DefinedTypes.Select(t => t.AsType());

public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly) { try { #if NET40 return assembly.GetTypes(); #else return assembly....
4
votes
1answer
605 views

Should reflection be part of design?

I'm currently designing a somewhat large program that will involve the simulation of math/physics models and collection of data (I have not implemented any code yet). One of the main problems I'm ...
11
votes
1answer
464 views

What's the relationship between meta-circular interpreters, virtual machines and increased performance?

I've read about meta-circular interpreters on the web (including SICP) and I've looked into the code of some implementations (such as PyPy and Narcissus). I've read quite a bit about two languages ...
3
votes
2answers
1k views

Reason for a reflection error

I’m working on an Eclipse plug-in project. Using this plug-in, users can create Eclipse Java projects with some specificities. For example, they can add Java classes’ names which will be saved in a ...
1
vote
4answers
991 views

Using Java Reflection to decouple code modules

I'm involved in a project with several modules. I found that programmers have designed one module to be easily decoupled from its dependent modules using Java Reflection. If other modules need to call ...
0
votes
3answers
391 views

How do I support interfaces for different devices in the same input scenario?

I asked this question on SO but someone pointed out that I would be better off here. He's most likely right. So here I go! So I just wanted an opinion. I have 2 different ways to approach the problem....
6
votes
4answers
3k views

Is it bad programming practice to check if a class referenced by its interface is an instance of another class?

I have a class (Timer) with an array list of Timable objects. Timeable is an interface. There is some specific functionality that I need for the Trigger class (implements Timable), which has a ...
-1
votes
1answer
164 views

Writing data driven reflection based tests to ensure design completeness [closed]

When writing software I'm often forced to at some point to make a decision that involves a design pattern of "by convention" naming and behavioral patterns. This normally makes me feel kind of slimy ...
3
votes
4answers
608 views

Is storing types in the database an anti pattern?

A little background on where this question is coming from. In my current .NET application I'm working on some features related to archiving a certain type of business entity called a "Project". ...
14
votes
5answers
15k views

Is it a bad habit to (over)use reflection?

Is it a good practice to use reflection if greatly reduces the quantity of boilerplate code? Basically there is a trade-off between performance and maybe readability on one side and abstraction/...
3
votes
6answers
1k views

In Java, would you sacrifice type safety for a nicer programming interface

When and why would you generally sacrifice typesafety for a nicer programming interface? Let me give you an example: if you had the choice between two event aggregators, which one would you prefer ...
3
votes
2answers
183 views

Determining which decorator classes are available via reflection

I'm creating a pizza place application where employees will be able to create orders for customers(pizza and any number of toppings). This is for a school project but the requirements have nothing to ...
5
votes
2answers
2k views

How to create contracts in python

I am currently learning Python (from Java) and have a question on contracts. Example: an application defines an interface that all plugins must implement and then the main application can call it. ...
7
votes
2answers
1k views

Are there any reliable solutions for annotations/reflection/code-metadata in C?

Not all languages support java-like annotations or C#-like attributes or code metadata in general, however that doesn't mean it is not possible to have in languages that don't have this. An example ...
18
votes
3answers
19k views

Reflection: Is using reflection still “bad” or “slow”? What has changed with reflection since 2002?

I've noticed when dealing with Expressions or Expression Trees I'm using reflection a lot to set and get values in properties and what have you. It has occurred to me that the use of reflection seems ...
3
votes
2answers
695 views

Reflection and the LGPL

Simply, If I use reflection to add methods or functionality to a class defined in a LGPL'd library I'm linking to, does that count as a modification to the existing library and would my reflective ...
24
votes
6answers
39k views

Why should I use reflection?

I am new to Java; through my studies, I read that reflection is used to invoke classes and methods, and to know which methods are implemented or not. When should I use reflection, and what is the ...
4
votes
2answers
371 views

Is it bad practice to use reflection to do DB inserts with data from an external service?

Our supplier's webservice is returning address objects (~30 fields) and I'm using LINQ and reflection to store the returned data straight into the databse. I loop over the attributes and set the value ...
24
votes
5answers
5k views

Is Java instanceof operator considered reflection, and what defines reflection?

I had a discussion with a coworker today, whether usage of using the Java operator instanceof is a kind of reflection. And the discussion quickly evolved into what actually defines reflection. So, ...
12
votes
3answers
398 views

Do I need to deal with the situation where private methods are called through reflection?

When creating a library, must I ensure that the private methods must work as expected when called not by other methods of the same class, but by another library through reflection? For example, if a ...