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
3
votes
0answers
36 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
1answer
62 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
2answers
85 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
2answers
70 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> { /* ... */ } ...
2
votes
1answer
92 views

Pass class property as parameter to extension method

I have the following class structure: MyAttribute.cs ...
9
votes
1answer
2k 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 ...
1
vote
2answers
6k 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 ...
1
vote
1answer
253 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
2answers
64 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
1answer
120 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
1answer
106 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
0answers
83 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
0answers
33 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 ...
7
votes
4answers
6k 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 ...
5
votes
0answers
136 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
2answers
267 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
3answers
191 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 ...
10
votes
5answers
16k 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
3answers
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
0answers
29 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
2answers
3k 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
2answers
631 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
2answers
114 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
5answers
114 views

PHP function to obtain model_name from Namespace\To\ModelName

Would there be a more clear/efficient way to write ...
5
votes
2answers
502 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
1answer
74 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 ...
11
votes
2answers
26k 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 ...
6
votes
3answers
344 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 ...
5
votes
2answers
1k 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. ...
6
votes
2answers
29k 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 ...
3
votes
2answers
846 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 ...
4
votes
1answer
98 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 ...
6
votes
1answer
172 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 ...
14
votes
1answer
47k views

Method that returns description attribute of enum value

I have the following method in .NET Core that returns the description attribute of an enum value. I think this code can be more elegant. I'd appreciate some ...
2
votes
1answer
65 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)...
1
vote
1answer
43 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 ...
6
votes
3answers
4k views

Generic extension method that will attempt to parse a string and return it's value or default(T)

So I got sick of several things about the way TryParse works. I implemented a generic ParseOrDefault function using reflection. It appears to work as expected, but I'm not fool enough to say my code ...
13
votes
6answers
122k views

Generic Null/Empty check for each property of a class

I have created a method to check for null/empty values of class properties and if any null property is found I'm stopping the checking process and returning the result as true. I've used a solution ...
3
votes
1answer
73 views
3
votes
1answer
87 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 ...
11
votes
4answers
5k views

Using reflection in a test to check if a private variable is really null after a function, is this okay?

I am using reflection to check if a private variable is set to null after the logout function. This is needed because the getUser function will always attempt to set and return an user if no user is ...
11
votes
3answers
129 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 ...
3
votes
0answers
146 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 ...
5
votes
3answers
307 views

Determine the class hierarchy of a class

My only concern with the following class is the line hierarchy.trimToSize() in determineHierarchy, because it is not necessary ...
3
votes
1answer
35 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 ...
4
votes
1answer
84 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'...
2
votes
1answer
82 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! ...
5
votes
1answer
1k 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: ...
1
vote
3answers
61 views

Finding the name of a given constant using reflection

The code below comes from the Arm_const class of my Android disassembler project: ...
1
vote
0answers
64 views

Dependency resolver in PHP

I wrote a simple Dependency Resolver in PHP that I'm hoping to get some input on. The main problem that gave me some trouble was when it had to resolve typed arguments ( like type hinting a ...

1
2 3 4 5