Skip to main content

Questions tagged [reflection]

Reflection is the process by which a program can observe and modify its own structure and behavior at runtime.

Filter by
Sorted by
Tagged with
9 votes
1 answer
5k views

Variadic macro enum class "reflection" in C++11

I recently had the need of "reflecting" multiple enum class constructs in order to get their elements' names as std::string ...
Vittorio Romeo's user avatar
4 votes
2 answers
146 views

Can my string to instance construction be improved?

I have a Dictionary<string, object> (named tableDict) that has been parsed from JSON. The ...
Joe Shanahan's user avatar
0 votes
1 answer
930 views

Java reflection: Inject data generically and safely [closed]

I have become interested in reflection and I wrote a class to wrap an Object so that I can access its private instance fields. The code works great. I do not need to wory about the exceptions in the <...
Mr. Polywhirl's user avatar
3 votes
1 answer
59 views

Collect all fields having given Modifier(s)

I want to collect all fields which have given Modifier(s) of a class. I have written following pieces of codes: ...
Tapas Bose's user avatar
7 votes
2 answers
10k views

Function that builds dictionary based on lambda params

I've written a method in c# that allows me to do create a dictionary from a passed in object and N lambda expressions that reference that objects properties and methods. It's working the way I want it ...
Ronnie Overby's user avatar
3 votes
1 answer
97 views

How can I improve my Java MethodPointer?

This was just an experiment to see if I could replicate something like C++ function pointers in Java. Basically, the idea was to have an object which represented a method call, and when you call <...
asteri's user avatar
  • 4,899
2 votes
1 answer
1k views

Is this the right way to retrieve all the fields from any Object?

I have a method that returns a List<Object> from any given Object containing its values. It doesn't get the values of any <...
Luiggi Mendoza's user avatar
8 votes
1 answer
621 views

Improve this reflection bashing code

I have implemented an IDataContractSurrogate to enable serialization of ImmutableList<T> (from the Microsoft Immutable ...
bradgonesurfing's user avatar
10 votes
3 answers
3k views

Converting between data and presentation types

Below is how I'm solving the problem of converting between data and presentation types, I'd like to know if that's a good way to go about it, and if not, what would be a better way to go about it. I ...
Mathieu Guindon's user avatar
2 votes
2 answers
2k views

Extension methods for class Type

While working on one of my projects I actively used Reflection. While working with class Type I expected methods: TryGetMember, <...
Leri's user avatar
  • 287
2 votes
1 answer
3k views

Java reflection and static classes

I try to intercept some OpenGL calls for testing my rendering classes. Reflection is used for replacing the OpenGL backend. I feel this class is badly written and I need advices for refactoring it. <...
sylvain's user avatar
  • 79
3 votes
1 answer
140 views

How to avoid echoing JavaScript from PHP?

I want to use some constant in both server side and client side. Currently, I use PHP reflection in order to synchronize PHP constants and Javascript constants. But for the maintainable reason, it's ...
hungneox's user avatar
  • 171
2 votes
1 answer
647 views

PHP ORM like system

I'm using PDO, but I want to create my own class for more convenient work with the database. My main idea in example with comments: ...
user0103's user avatar
  • 176
-2 votes
3 answers
908 views

New to LINQ, not sure this is best practice

So i have a super class that has a 3 child classes. Those 3 child classes have multiple classes of their own. I was having troubles saving this into XML, so I decided to parse it out and do a little ...
Robert Snyder's user avatar
2 votes
1 answer
407 views

Multiple target method invocation wrapper

I'm currently working on a system using WCF to communicate between a Windows Service and one or multiple clients. Service is required to answer clients calls, as well as notify them of certain events, ...
slawekwin's user avatar
  • 123
2 votes
1 answer
74 views

ORM Entity with many similar relationships

To provide some background context, I'm implementing a web-based solution (Java, Spring, Hibernate) that allows the creation/authoring of task-centric workflow documents. Basically a workflow ...
aroth's user avatar
  • 586
8 votes
1 answer
628 views

Evaluate the best common type to fit both of types

Here is an algorithm to evaluate best matching System.Type for two types in hierarhy. This is one of answers for this StackOverflow question by Ken Kin: Evaluate ...
Akim's user avatar
  • 475
13 votes
1 answer
7k views

Inject dependency into PostSharp aspect

I have designed couple of aspects using PostSharp for different projects, but there is a design flaw in many of them: dependency management. This is a question about injection of dependencies into ...
Akim's user avatar
  • 475
7 votes
2 answers
171 views

Action based controller using reflections

I'm modeling a reflection-based controller. I would like to know if you agree with my implementation and about what could be enhanced. I'm starting with reflection and I would like to know if I'm ...
user1618606's user avatar
1 vote
1 answer
449 views

PHP class and interface interrogation using reflection

I have been working on a class to use Reflection to interrogate other PHP classes and interfaces, what I want to know from anyone with more experience of this is, is there anything else I can add, or ...
TG Wolf's user avatar
  • 11
1 vote
1 answer
1k views

Lazy loading with __get

I have my own PHP MVC framework that I'm iteratively developing (i.e. adding a feature when I have the time). I'm trying to keep it to the best practices I can, while still adding the most in terms of ...
Naltharial's user avatar
4 votes
1 answer
7k views

Usage of Expression<Func<T>>

I am developing data-interfacing that converts between two different data models. However, I must be sure that all required fields exist. Therefore I have written this utility class that I can easily ...
Myrtle's user avatar
  • 528
4 votes
2 answers
4k views

Ruby Fibonacci(n) recursive computation optimized with reflection

The idea is to take the common-known (and awfully bad performing) Fibonacci(n) recursive method: ...
Darme's user avatar
  • 285
3 votes
2 answers
12k views

Casting an Enumeration with Descriptions into a Dictionary

The Enumeration in question is based on int, so the following Extension returns a Dictionary<int, string> of the Enum's ...
kalyfe's user avatar
  • 133
6 votes
1 answer
486 views

Basis of custom C++ serialization lib

I know it's been done a million times already, but I couldn't find a serialization library to suit my needs. This is the very basis of what I came up with. I know the code is ugly and unstructured, so ...
kalmard's user avatar
  • 161
8 votes
2 answers
2k views

Attribute driven behaviour in C# methods

We want to create a TransactionScope factory class that we can use as a central point for instantiating TransactionScopes with ...
Eoin Campbell's user avatar
4 votes
1 answer
10k views

Query String Serializer

I have a ASP.NET Web Forms project, and I want to build calls to .aspx pages in a strongly-typed fashion. I ended up rolling my own serializer that takes simple structs and saves them to/loads them ...
Daryl's user avatar
  • 143
18 votes
4 answers
31k views

Returning Groovy class fields as a map

I want to get a map of all the fields in a class (aka value object) in a generic way. The following works fine for me: ...
neu242's user avatar
  • 291
4 votes
2 answers
748 views

C# overload method simplification

I have the following routine that I would like to simplify: ...
Luca's user avatar
  • 204
7 votes
2 answers
278 views

Dispatcher for a JSON API without routes

I am using this code for a fast JSON API without routes. Does this code contain any useless parts? Is the class loader efficient enough? Are there any better options? Is ...
Aalex Gabi's user avatar
4 votes
1 answer
486 views

Find log4net logfiles at runtime without adding dependency to project

I was searching for a way to get all active log4net logfiles (if any) at runtime without adding a reference to the project. This is the solution I came up with: ...
yas4891's user avatar
  • 141
1 vote
2 answers
8k views

Replace all occurrences with the properties of an object

The basic idea is to replace all special expressions, e.g., [%InvoiceNo%], [%DueDate%], in a string with the properties of an ...
walterhuang's user avatar
2 votes
0 answers
879 views

ORM with magic getters/setters

I'm playing around with PHP, trying to write a small ORM. Having worked with Magento quite a bit lately, I've fallen in love with the automagic getters/setters that Magento, I think, inherited from ...
vzwick's user avatar
  • 119
3 votes
1 answer
399 views

Method to lookup persistent entities by an example object

i'm currently writing a generic data access object for the persistent entities I have to handle in my JavaEE application. What this codeReview is about is a findByExample method that is used to find ...
unR's user avatar
  • 133
2 votes
1 answer
6k views

Creating Extension Method to map entity with subentities object to Poco object

I am trying to create an extension method that builds a POCO object (copies all the fields) for an Entity Object. When Entity object is simple (no navigation, no sub collections), it works fine. I ...
user avatar
6 votes
1 answer
16k views

Is there a better way to convert to a specific type with reflection?

Rather than doing what is essentially a large switch statement for every possible type, is there a better more generic way of converting to a specific type with reflection? I've looked up ...
Jim Wallace's user avatar
5 votes
2 answers
10k views

Casting to less generic types

The source code, or rather the concept I'd like to get reviewed is what now allows me to do the following during reflection: ...
Steven Jeuris's user avatar
14 votes
2 answers
36k views

Mapping ExpandoObject to another object type

I am working on a helper method that maps properties from an ExpandoObject to a user supplied object and was wondering if the code could be cleaned up or made any ...
Tom Bell's user avatar
  • 243

1 2 3 4
5