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
1 answer
122 views

Add field and value into an object by reflection

original code: import, hide some irrelevant company package ...
leaf_yakitori's user avatar
0 votes
1 answer
3k views

Copy object without reference using reflection

Recently I was in need of a method to copy an object and pass it to a method which alters the data. Since a class is passed by reference this would alter the class in the caller which I don't want. So,...
Roe's user avatar
  • 121
0 votes
1 answer
130 views

Readlines abstraction for Golang

I've just started learning Golang and was solving some problems which required me to read lines of text from a file. I decided to abstract away the reading part so that I can use Go's ...
smac89's user avatar
  • 1,509
1 vote
1 answer
68 views

Mapping various input values to a data accumulation class

This function takes inputs from multiple different controls on a form, and maps them to values in a data accumulation class. This code was written specifically to keep logic, data, and display ...
EvilPCDiva's user avatar
3 votes
0 answers
203 views

Simple Java IoC container for dependency injection

I have come up with a quick and simple IoC container to enable minimal dependency injection support in one of my Java projects. The container supports services with: A transient lifetime, meaning, a ...
Amal K's user avatar
  • 173
1 vote
0 answers
483 views

Entity Component System (ECS) in Java

While trying to write a game engine, I came up with this ECS / Component Based Architecture for its physics and drawing logic. I want to get some feedback on its architecture. I am using reflection ...
Quadslab's user avatar
  • 113
1 vote
3 answers
2k views

Best way to get an arbitrary property for a C# class?

I have close to a hundred classes where I need to get arbitrary properties from them at runtime. The calling class knows which properties it wants at run time, but not at compile time. Looking for ...
DKATyler's user avatar
  • 176
13 votes
1 answer
1k views

Low Level VBA Hacking - making Private functions Public

NEW: Download demo files Not sure what to title this - essentially, inspired by RubberDuck's unit test engine, I've created a way to call private methods of standard modules in VBA. It also lets you ...
Greedo's user avatar
  • 2,385
9 votes
1 answer
660 views

Change arbitrary arguments of function based on their names with a decorator

I ran across an issue that proved to be more complicated than I thought: Changing an arbitrary argument of a function purely based upon its name in Python - possibly via a decorator. I tried to ...
s-m-e's user avatar
  • 273
3 votes
1 answer
1k views

Setting all class members to null to destroy strong references

At work we are using Xamarin.iOS for our apps. We frequently have to fight it's disadvantages, namely it's memory leak issues where strong cyclic references keep objects alive and prevent them from ...
Frederik Hoeft's user avatar
3 votes
2 answers
93 views

Search code that performs in-memory search

This is the code I came across in our repository. This performs search in-memory and is invoked on service layer code. In our front end operators like EQUAL_TO and ...
user251118's user avatar
0 votes
1 answer
81 views

How to save/get different type of data with less duplicated code

description: I'm using thrift to save and get data by filter. The data have many types, and the types may increase in the future. So I use ...
leaf_yakitori's user avatar
0 votes
1 answer
1k views

Exists Method Implementation for Multidimensional Array in C#

To determine whether the specified array contains specific element or not, Array.Exists can be used if the given array is one dimensional. I am attempting to implement ...
JimmyHu's user avatar
  • 4,708
1 vote
1 answer
97 views

Class showing a format similar to var_dump v1.0.5

First of all I must thank for the help given in the previous post: Class showing a format similar to var_dump RC5 Version I have it deployed in a early versio v1.0.5: https://github.com/arcanisgk/BOH-...
user avatar
0 votes
1 answer
766 views

Increment struct value using reflection

The main idea is, I have a struct and I will get a struct field as a string from another function, which I shall increment its value by 1. Below is the code I used and I think it is memory consuming. ...
Medhat's user avatar
  • 123
4 votes
1 answer
78 views

In-proc event dispatching through IoC container

Here is the sender and handler interfaces: ...
Dmitry Nogin's user avatar
  • 6,131
2 votes
0 answers
47 views

Performance impact of using reflection instead of an "Options" class

I am trying to refactor a service by providing some options on what to bring back. I can't decide what is best way to go between the below A. Use a class for the options Create a new class for the ...
Anastasios Selmani's user avatar
3 votes
0 answers
120 views

Yet another reflection library

Tried to do my own implementation of reflection(introspection) for using in my next projects. Is it optimized at compile time? If no, how can I improve it? This macro is good interface for adapting ...
Vladyslav Mozhvylo's user avatar
3 votes
1 answer
550 views

C# Reflection-based CSV Parser

I've been trying to make a C# version of my Java CSV Parser using C# specific idioms. Here is the full code: ...
Richard Robinson's user avatar
3 votes
2 answers
432 views

Java Reflection-based CSV Parser

I'm an experienced Java developer, however I don't have experience with reflection or Annotation classes. For fun, I tried to develop a CSV Reader class which can parse each row into a particular type....
Richard Robinson's user avatar
3 votes
2 answers
657 views

Find all classes A that implement B<T> and aggregate both A and T to build a map out of them

In my project I have the following base interfaces used through the application: interface Node { /* ... */ } interface NodeService<T> { /* ... */ } ...
Christian Ivicevic's user avatar
1 vote
1 answer
2k views

Pass class property as parameter to extension method

I have the following class structure: MyAttribute.cs ...
Igor's user avatar
  • 182
4 votes
2 answers
87 views

Feedback on automatic form filling with reflection

Context: I need to fill a handful of .docx templates with answers that come from form.responses, which is a dynamic object that comes from a JSON and can have different properties that vary according ...
lsfgrd's user avatar
  • 41
0 votes
1 answer
1k views

To convert all the class properties to IDictionary<string, dynamic>

I have the requirement to return the result of my ViewModel as a Dictionary of KeyValue pairs. My view model comprises of multiple classes and can have null values in properties. I need to return only ...
Sahil Sharma's user avatar
1 vote
0 answers
233 views

Generics and aggregated evaluation of validation rules

I have a custom system for data validation; it handles anything from method parameters, return values, objects, etc. The core of this system is IValidationRule and ...
pikausp's user avatar
  • 219
2 votes
0 answers
65 views

Library/API: simple springboot / jdbc query builder and ORM

I have been using and developing a simple ORM and query builder library that I have found useful in it's practical application. I am pretty sure there are improvements to be made, and I welcome any ...
rmalchow's user avatar
  • 121
5 votes
0 answers
254 views

Factory class that uses reflection to instantiate objects by class name

In this SO post Dynamically choose class from string Alexander Platonov creates a Function on the fly and then uses Application.Run() to instantiate an Object by ...
TinMan's user avatar
  • 4,133
9 votes
2 answers
335 views

Immutable builder and updater

There aren't enough questions about creating immutable objects... so why not try it again with another approach. This time, it's a builder that maps properties to constructor parameters. Properties ...
t3chb0t's user avatar
  • 44.3k
2 votes
3 answers
656 views

Simple middleware pipeline builder (similar to asp.net-core)

I created a simple middleware pipeline builder that I want to use for my frameworks. It is similar to how ASP.NET-Core middleware works and uses the same conventions: A public constructor with a ...
t3chb0t's user avatar
  • 44.3k
4 votes
0 answers
87 views

Inherit docstrings from specified parent

I was recently working on some python where I was working with multiple inheritance and mixins and stuff like that, and I wanted to inherit docstrings for specific functions, from specific parents (...
Andrew's user avatar
  • 61
4 votes
2 answers
406 views

Registering Named services and resolving them by T

Problem statement I have an application that needs to get files from various sources (disk, embedded, http, ftp, ...) so I use a common API for them: ...
t3chb0t's user avatar
  • 44.3k
5 votes
2 answers
601 views

Reducing using/foreach/using nesting with a helper extension

Problem statement There are sometimes foreach scenarios that require deep nesting due to multiple disposable objects involved that look like this: ...
t3chb0t's user avatar
  • 44.3k
1 vote
5 answers
3k views

PHP function to obtain model_name from Namespace\To\ModelName

Would there be a more clear/efficient way to write ...
Grey's user avatar
  • 217
6 votes
2 answers
4k views

Fetch and print all properties of an object graph as string

Below I have setup an extension method that takes any object, cycles through its properties, and prints each out to a Console window in the format Name: Value. ...
Delfino's user avatar
  • 509
6 votes
1 answer
1k views

Enumerate all members and types with specific attributes

I have a use-case where I need to retrieve all members with specific attributes in the class and interface hierarchy - I usually need the first match and apply its rules to child members. The built-in ...
t3chb0t's user avatar
  • 44.3k
6 votes
3 answers
364 views

Calculating time windows for entities

I have made some code that operates on multiple entities and creates 'time windows' for them. Basically, the entities will contain states, usually in boolean or int. They will be timestamped and in ...
Mark Cilia Vincenti's user avatar
2 votes
1 answer
89 views

Populating dropdown lists, using SQL vs. using expression trees and reflection

I'm working with a large enterprise SQL Server database with dozens of tables that are used mainly as lookups to populate dropdown lists, etc. These tables all follow the convention of having (table)...
Valuator's user avatar
  • 189
1 vote
1 answer
50 views

Update any controls' Text for the specified language [closed]

I would like to optimize the below code The only difference is the datatypes RadioButton, Label, and Button. Outside the method I have an loop that iterates over all the controls in the aspx-page. I ...
Jon's user avatar
  • 119
3 votes
1 answer
122 views

Assigning test-data parameters by name

When creating data-driven tests with xUnit we can use the MemberDataAttribute to get the data from a member of this or other ...
t3chb0t's user avatar
  • 44.3k
3 votes
1 answer
218 views

Settings class implementation

I have a settings.txt file with the following format: ...
potato's user avatar
  • 1,122
3 votes
1 answer
127 views

Exploring code objects

The first version of my solution was wrong (the usage of compile() function), for details see Stack Overflow. The solution has been fixed and now it works ...
MiniMax's user avatar
  • 862
11 votes
3 answers
1k views

Simple generic auto __repr__

Preface At some point I was tired of writing & supporting __repr__ methods, so I've decided to write it once and reuse everywhere in my classes. Since I'm ...
Azat Ibrakov's user avatar
3 votes
0 answers
635 views

Generic object-to-XML mapper

This code is part of a larger mapping library I'm working on to address some business concerns of transforming data. I was inspired by mapstruct in Java, but opted for users to annotate / add ...
Igneous01's user avatar
  • 131
2 votes
1 answer
562 views

Class to fill model objects with data from the database

This is a helper class that helps fill models with data obtained from the database. ...
MadLax's user avatar
  • 129
3 votes
1 answer
3k views

Snippet to get all local classes from a module

I'm working on a project which due to the complexity of the business logic has had to pull out some classes to do computation related to some values in a database. To link the code and database, both ...
l0b0's user avatar
  • 8,927
4 votes
1 answer
112 views

Immutable type updater using a special constructor

I wanted to update some properties of my UriString but since this type is immutable, it wouldn't work. Actually, I just wanted to update the Path property but I don'...
t3chb0t's user avatar
  • 44.3k
2 votes
1 answer
126 views

Reflection optimization for export CSV on large scale

So, I'm building export/import CSV helper. I have some performance issues in the code below. it takes me to parse CSV of 25,000 rows at 7 seconds. If someone can help, it will be awesome! ...
o.Nassie's user avatar
4 votes
1 answer
289 views

Dynamic setting names based on properties

In one of my frameworks that I use with many tools I have an ExpressionVisitor whose job is to resolve the exact property, it's declaring type and instance. I ...
t3chb0t's user avatar
  • 44.3k
6 votes
1 answer
2k views

Making TypeNameHandling in json.net more convenient

Handling abstract types in json.net can be sometimes challenging because it requires a very long and complex syntax like: ...
t3chb0t's user avatar
  • 44.3k
-2 votes
1 answer
329 views

Using Reflection to call multiple methods and cast various classes [closed]

I have written the following Reflection code: ...
Joehot200's user avatar
  • 107

1
2 3 4 5