Questions tagged [reflection]
Reflection is the process by which a program can observe and modify its own structure and behavior at runtime.
236
questions
0
votes
0
answers
17
views
PHP And Reflection For Showing Available Formatters On A Report Column
I'm using reflection in PHP to load a list of available Formatter classes that all have methods that do formatting of a value in a specific CSV column.
e.g. for ...
3
votes
1
answer
840
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 ...
0
votes
1
answer
2k
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,...
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 ...
0
votes
1
answer
118
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 ...
3
votes
3
answers
3k
views
Reflection optimization
In a web application I'm working on I have a class that Map objects to other (different) objects. It is implemented with something like:
...
10
votes
1
answer
260
views
Linq-to-Sage Implementation
Following-up on my last question where I wrapped the Sage API with a familiar IRepository interface, I decided to push the abstraction a step further, and... ...
1
vote
1
answer
64
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 ...
4
votes
1
answer
92
views
Request handler based solely on reflections ver. 2
This question is connected to the previous one: Request handler based solely on reflections
I have edited the code, taking tim's answer in regard, editing the Kernel class cohesion.
...
9
votes
5
answers
10k
views
Instantiating a C++ class based on an enum value
I have a bit of code duplication and trying to figure a better way to reduce it. I'm looking for any suggestions. If this was in Java I could easily use reflection.
The code posted is a basic ...
6
votes
2
answers
595
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 (...
3
votes
0
answers
189
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 ...
1
vote
0
answers
402
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 ...
1
vote
3
answers
1k
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 ...
9
votes
1
answer
476
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 ...
13
votes
1
answer
53k
views
Python class initialize with dict
how can I express this idea in Pythonic way?
The problem is that I want to create class with many attributes, but don't want to initialize all in __init__(self, arg1, arg2, ..., argN). Instead of this ...
3
votes
2
answers
86
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 ...
14
votes
2
answers
35k
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 ...
0
votes
1
answer
80
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 ...
12
votes
1
answer
4k
views
Mimic C#'s nameof() in Python
I rewrote some code I posted earlier this month. It attempts to mimic C#'s nameof() by extracting names from bytecode instructions.
This seems more reliable than ...
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:
...
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 ...
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-...
0
votes
1
answer
686
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.
...
4
votes
1
answer
78
views
In-proc event dispatching through IoC container
Here is the sender and handler interfaces:
...
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 ...
3
votes
0
answers
100
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 ...
3
votes
1
answer
531
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:
...
3
votes
2
answers
398
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....
3
votes
2
answers
334
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> { /* ... */ }
...
1
vote
1
answer
2k
views
Pass class property as parameter to extension method
I have the following class structure:
MyAttribute.cs
...
1
vote
2
answers
7k
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 ...
2
votes
1
answer
367
views
Kotlin reflection to generate one class from class similar with similar properties
This code is intended to generate a class (domain) from a class with class with similar/identical properties (api). Motivation is to speed development time when using clean architecture.
...
4
votes
2
answers
86
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 ...
0
votes
1
answer
946
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 ...
2
votes
1
answer
528
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.
...
1
vote
0
answers
216
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 ...
2
votes
0
answers
56
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 ...
5
votes
0
answers
233
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 ...
9
votes
2
answers
333
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 ...
2
votes
3
answers
635
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 ...
11
votes
5
answers
30k
views
Convert a custom object to a query string
I wrote an extension method that takes a custom object and converts its properties to a query string for use in a URL. You can specify what properties you want included by using a ...
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 ...
4
votes
0
answers
81
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 (...
4
votes
2
answers
6k
views
Test all properties with single test function
In writing unit tests for c# functions, there is a good case made for testing properties. In testing those properties, I felt there should be a few goals.
Provide a wide range of inputs
Test ...
3
votes
2
answers
962
views
Python deep get
I'm implementing deep_get functionality to look inside arbitrarily nested Python 2.7 objects. Primarily for further logging.
This turned out to have surprising ...
4
votes
2
answers
294
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:
...
1
vote
5
answers
2k
views
PHP function to obtain model_name from Namespace\To\ModelName
Would there be a more clear/efficient way to write
...
5
votes
2
answers
583
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:
...
3
votes
1
answer
119
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 ...