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
2 votes
2 answers
114 views

Method for finding all classes

This was inspired by a Stack Overflow question about getting all the classes of an application and I took it a little too seriously (or perhaps not seriously enough). It's rather silly to do it this ...
jperl's user avatar
  • 435
10 votes
3 answers
3k views

Listing human-readable enums

I'm trying to do some util class to operate on enums - convert Enums to its special strings representation via interface method. String stored in enum constructors. ...
Alex Silkovsky's user avatar
1 vote
1 answer
2k views

Create Form Controls based on the properties of a class

Is there a better way to create Form Controls for properties of a class? Right now, I iterate through all properties of a class and have a method to create the Form Control for that property based on ...
vice_versa's user avatar
8 votes
2 answers
902 views

Strict types decorator (works only with Python 3.5)

I wrote a decorator which makes Python 3.5 raise exceptions if the arguments that are passed to a type-hinted function are of the wrong type. ...
Ilya Peterov's user avatar
2 votes
1 answer
834 views

Method that return related entities using OData

There is method GetFull that should use OData return related entities. When I call GetFull(12, "entity1,entity2") then I will ...
Roman Marusyk's user avatar
2 votes
1 answer
52 views

Find foreign key membership including owner in SQL Server

Was hoping someone could sanity-check this SQL statement. I need to find the owner (schema), table, and column on both sides of a foreign key: ...
Fred Lackey's user avatar
7 votes
2 answers
19k views

Setting the value of properties via reflection

I am working on an application in which I have to parse an XML file. Nodes of the XML file corresponds to an object. I have to populate the properties of the objects at run time. The code below ...
Sandeep's user avatar
  • 410
5 votes
1 answer
138 views

Generating controls based on PropertyInfo

This is a class that takes a PropertyInfo and makes a Control for it. You can access the value of the control through a property on the class called Value. ...
andypopa's user avatar
  • 153
7 votes
1 answer
6k views

Getting all public constants from the main and nested classes

I wrote this recursive function to get all constants from a class and its subclasses. Can it be simplified? ...
Иван Грозный's user avatar
5 votes
1 answer
121 views

Project Euler: Autorun problems

I've found that it's a huge pain to have to write the boilerplate code for each Project Euler problem I write (timing code, main method, what about running every problem instead of just one?). So I ...
Justin's user avatar
  • 3,295
8 votes
1 answer
2k views

Dynamic data object generation

Last weekend I had an idea: Why not remove dozens of classes by removing all the basic get/set/equals/hashCode implementation of my data object interfaces? I tend to code against interfaces, so I ...
Florian Schaetz's user avatar
4 votes
0 answers
91 views

Creating companion classes that are `inherited` onto any sub-classes

The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
br3nt's user avatar
  • 242
4 votes
2 answers
491 views

Set Game State from String

Before I used reflection to invoke a state based on the string, it looked like this: ...
Emz's user avatar
  • 1,024
4 votes
4 answers
3k views

Python Decorator - inspecting function argument values

Some of my functions use a "fail_silently" flag. It is used in the following way: ...
user1639926's user avatar
6 votes
2 answers
3k views

Recursively merge dictionaries with generic types in C#

I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
Laurens Vergote's user avatar
2 votes
0 answers
14k views

Retrieving Primary Key from Entity Framework entity

Entity Framework (version 6) generates classes based on your tables that look like this (where each property represents a field in the table): ...
Kai's user avatar
  • 449
7 votes
1 answer
3k views

JSON serializer using generics rather than System.Object

I recently created a custom static class in C# to encode, hopefully, any object it is given (or collection of objects), because I was, at the time, unaware of a native C# library that did the same ...
Joshua Kemmerer's user avatar
4 votes
1 answer
125 views

Porting a web-based POS system to Android

I'm currently porting a web-based POS system to Android. The Android version uses NavigationDrawer to navigate between menus. What I need a code review on is my ...
TtT23's user avatar
  • 1,040
4 votes
3 answers
4k views

Property Mapping with Reflection efficiency

I have an object that I am populating via mapping and lookup with Reflection: ...
Isaac Levin's user avatar
2 votes
2 answers
1k views

config.properties, Static Classes and Reflection

I wanted an opinion about an idea I had regarding the use of config.properties, static classes and the use of reflection. I have to load some preferences at application startup, for that I will be ...
San Mor's user avatar
  • 39
6 votes
2 answers
260 views

Building in the built-in declarations

In order for Rubberduck to be able to "recognize" the built-in VBA functions, procedures and objects, I added yet another constructor parameter to my Declaration ...
Mathieu Guindon's user avatar
9 votes
2 answers
2k views

Optimize a generic foreach method that converts Datatable to my object using Reflection

I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
Roger's user avatar
  • 195
5 votes
2 answers
604 views

Type Name or Alias via Reflection for TT Code Generation

I was working on some TT code generation to get rid of mundane C# codings in VS2013 Express Edition, and after researching online, created the following helper methods to facilitate Type declarations. ...
Alex's user avatar
  • 51
2 votes
1 answer
1k views

Implementing transaction method with invoking business methods in a one transaction

Because the ambient transaction isn't supported with informix, I pass the transaction and the connection through my methods. I ...
Anyname Donotcare's user avatar
5 votes
2 answers
2k views

Java MVC model for large scale GUI using annotations

I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts ...
AwaX's user avatar
  • 151
5 votes
3 answers
264 views

Avoid static initializer for lists of image and video formats?

I wrote the following code to read constants from annotations: ...
gstackoverflow's user avatar
9 votes
2 answers
1k views

Generic queries and handlers without reflection

I'm trying to implement generic queries and handlers so that I can make requests with simple syntax, like this: ...
Bryan's user avatar
  • 231
3 votes
2 answers
329 views

Validator part 2

This is a follow up to: Validating individual properties and whole items I have a custom class I've written which allows me to validate individual properties of items, without firing validation ...
Nick Udell's user avatar
  • 5,197
2 votes
0 answers
58 views

'Tag' packages and make them discoverable

We have another team who is going to expose class packages for use to scan and pickup details from. If they should add some new packages or rename old ones I don't want to have to recode a thing. I am ...
Christian Bongiorno's user avatar
3 votes
2 answers
225 views

Function caller (to multiple receivers) interface

This class is designed to call a similar function of multiple objects of multiple classes using a single interface (it is not for calling functions that return a value). A potential usage will be ...
JaDogg's user avatar
  • 4,531
11 votes
2 answers
108k views

Check if any of class properties is not null/empty/was assigned

I have a class that I use to display on a web page fieldset. However, all of the properties of this class are optionally filled in by the user, which means all of them could be null/default. In this ...
victor's user avatar
  • 233
3 votes
2 answers
882 views

ComplexProperties with Reflections

I have used reflection for divide the complex property. For example, if I bind A.B[0], CustomerName means CustomerName is returned. Can anyone help to reduce the ...
Elavarasan M's user avatar
4 votes
2 answers
140 views

Reflection and Project Euler

I have made a Project Euler runner in order to facilitate the running of the various problems. I have never used reflection before, and I believe that I have found a good use for reflection within ...
Brendan Lesniak's user avatar
5 votes
1 answer
647 views

Autowiring publishers/listeners with reflection in Unity Framework

I'm currently building an application with the Microsoft Unity Framework. I also use a simple system of message publishers/listeners inspired from MVVM light and caliburn: The listener interface ...
IronSlug's user avatar
  • 151
5 votes
2 answers
681 views

Loading data into a number of different typed List<T>s: Can I do without reflection?

I'm not sure whether my distaste for reflection is justified or not, but it feels ucky that I'm using reflection here. I'm trying to make a very simple class which has a number of ...
Ashley Davies's user avatar
5 votes
2 answers
671 views

Evaluating algebra expression using an auxiliary VB class compiled on the fly and consumed in a C# project

I want to create algebra evaluator but I don't want to write my own parser because it takes much time to learn. I don't like algebra expression in C# because it does not look natural compared to VB ...
kiss my armpit's user avatar
6 votes
2 answers
30k views

Transform DataReader to List<T> using reflections

I have implemented the code to convert datareader to list of objects. My intention was to not to use column name string literals while reading the datareader. ...
gee'K'iran's user avatar
7 votes
2 answers
33k views

Find all collection properties of an object and get their values

I have a chunk of code that get's all of the ICollection properties of the passed in object and then takes all of their values and adds them to another ...
Gup3rSuR4c's user avatar
7 votes
2 answers
4k views

Using Reflection to Initialize Instance Variables

I'm facing the issue of how to reconstruct data across a network in Java. As part of my Component based game engine (read about it here, I have to encode components as XML on the server, send it to ...
psychicmachinist's user avatar
2 votes
1 answer
393 views

Speed problems with SetValue, ToType and Reflection

I have a 'speed problem' with a program I'm currently developing. I already have encountered the methods which costs some time. ...
Daniel W.'s user avatar
  • 161
4 votes
1 answer
4k views

Speed problems with SetValue, ToType and Reflection

I have a 'speed problem' with a program im currently developing. I already have encountered the methods which costs some time. ...
Daniel W.'s user avatar
  • 161
6 votes
2 answers
175 views

My EventBus system followup

This question is a followup from my previous question My EventBus system, and incorporates most points from @rolfl's answer. It includes, but is not limited to: Usage of ...
skiwi's user avatar
  • 10.6k
7 votes
1 answer
204 views

My EventBus system

I decided to roll out my own EventBus system which is intended to be thread-safe. Hence a review should focus extra on thread safety apart from all regular concerns. The ...
skiwi's user avatar
  • 10.6k
6 votes
5 answers
837 views

Initializing JTree

I have a class called Piece, and many many subclasses of Piece. I want to add an instance of every single subclass of ...
Kyranstar's user avatar
  • 1,191
8 votes
4 answers
9k views

Get nested type name without namespace

Suppose I have a nested class structure like this: ...
p.s.w.g's user avatar
  • 1,961
10 votes
2 answers
5k views

Override equals() and hashCode() using reflection

I wrote a utility method to override equals() using reflection. This works fine, but I wonder if this code will pass all the tests. ...
khushnood's user avatar
  • 123
4 votes
2 answers
597 views

comparing objects; optimize code short of using reflection

I'm comparing two distinct instances and if they are not the same I save to the dB, so I've given snippet of code below of the way I am comparing these instances, I realize I could use reflection and ...
user38158's user avatar
  • 137
5 votes
1 answer
280 views

Setting up keyboard bindings using JSON and reflection

My game uses configuration files in JSON format. One of them is used for setting up control bindings, and it looks like this: ...
Big McLargeHuge's user avatar
7 votes
2 answers
16k views

A generic way to use LINQ to Entity with types and operations unknown until run time

A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs. Here's what I am trying to accomplish: I'm writing back-end support ...
David's user avatar
  • 171
6 votes
2 answers
597 views

Using reflection to connect to an arbitrary backend

A little background first - I'm working on a server application that requires the ability to use multiple data access class libraries based on the resources available on the server it is installed on (...
Comintern's user avatar
  • 4,192