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
0 answers
83 views

Scala code that loops through Java annotations decorating Scala classes

I have code written in Scala that reads annotations decorating other Scala classes. These annotations are written in Java. The sticking point is that annotations don't allow advanced data structures, ...
3 votes
1 answer
276 views

Exposing .NET's internal StorageRoot via Reflection for accessing file/stream-based Structured Storage

.NET tantalizingly exposes StorageInfo and StreamInfo as public classes, but hides the ...
2 votes
1 answer
108 views

Setting value of controller controls for domain objects with Reflection

Is my use of Java Reflection an OK design? Each domain object contains an annotation to declare what controller would be initialized to edit/create the object: Each field of the domain object has ...
7 votes
1 answer
1k views

Decorator to return default argument values

I'm using Python 3.6. This code, used as a decorator to a python function, will cause the function to return a dict of POSITION_OR_KEYWORD arguments. I used this ...
2 votes
1 answer
115 views

Improvements for ugly reflection

I have a project that uses a library to save serialized objects in items and loads them again, when needed. To do the de-/serialization, this library uses Gson. Due to how Gson works and how the ...
-2 votes
1 answer
103 views

Addressing "System.NullReference" Resharper warning in function [closed]

TLDR: How can I check "DeclaringType" for null without causing a further cascade of problems in the function? I have a C# LINQ query that uses reflection to list all Areas, Controllers, and Actions ...
4 votes
2 answers
128 views

Simple object comparer

Creating a simple object compare function for public system types in a class meaning only looking at the first level of a class no breaking into an object and comparing sub properties. It performs ...
4 votes
2 answers
674 views

Converting recordsets to POCO

The goal this method was to emulate the way EF or Dapper return to you concrete POCO classes instead of recordsets when querying your db. Our current code is riddled with iterations over recordsets ...
1 vote
1 answer
114 views

Create a List of any type of object based on List of HashMap from JSON

I have this method that is working as i want: ...
5 votes
5 answers
7k views

Safely order a list of objects by DateTime

I have several lists of various objects that need to be ordered by one of their properties that contains a string representation of DateTime, whose property also ...
4 votes
1 answer
114 views

Sleeping and invoking a task in Python 2.X and Python 3.X

I'm writing a program that needs to be compatible for both Python 2.X and Python 3.X. My problem is that, because of the differences between these two versions, I'm duplicating code. ...
5 votes
1 answer
4k views

Building a model-view-controller application in PHP

I've seen at least two recent PHP questions that would do well from a Model-View-Controller ('MVC' from here-on-out in this question) setup. Now, me, being the horrible person I am, I wanted to build ...
9 votes
1 answer
14k views

Python proper abstract class and subclassing with attributes and methods

The goal of the code below is to have an abstract base class that defines simple methods and attributes for the subclasses. This is part of an application that provides the code base for others to ...
4 votes
0 answers
143 views

Dynamically creating login screen on Android devices

This has been an experience. I'm well above "hello world" java is not a language I use often when programming and I don't program too much. I find myself a lot on Google.... basically just about for ...
4 votes
3 answers
4k views

Accessing Properties by Name

Over the weekend I decided to start work on my own version of FastMember. I began with my take on an implementation of TypeAccessor so that I could work with the ...
2 votes
3 answers
4k views

Saving complex business objects with reflection and recursion

In our application we have complex objects with many nesting levels, each with various properties that are important to the business. We currently serialize and persist these objects along with their ...
1 vote
0 answers
2k views

Generate random instance of given Class

I was running some rightsizing tests and had to blast random objects of my various class types. Here is the code I came up with. ...
1 vote
1 answer
58 views

Declarative DependencyProperety registration

Most properties have simple requirements so it should be possible to register their Dependency Property fields declaratively. I made a small experiment and it seems to work just fine. The first ...
4 votes
2 answers
2k views

Dynamically convert property to different data type

The code finds marked attributes and parses them according to the attribute type. Is it possible to simplify this logic? Is there generic way to do it? Please suggest some way to optimise this code. ...
5 votes
1 answer
143 views

Illumination as a way of instantiating new objects

Basically, what I mean by illumination is having a method create an object where the caller supplies all the dependencies. This allows us to hide our new keyword ...
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. ...
3 votes
0 answers
105 views

Print Python docstrings when module is executed interactively

I have written a module, which should only be used by means of import, then call the functions as required. I do not want this module to do anything when ran interactively, other than printing out ...
1 vote
1 answer
5k views

Custom Exception.ToString() formatter

I find the default Exception.ToString() formattig very difficult to read especially if there are inner exceptions involved. I guess everyone knows how it looks: <...
7 votes
1 answer
4k views

Code that uses reflection to validate arguments

I wrote an answer to this question on the Software Engineering SE site and was hoping to get it critiqued. (I'm told that it's acceptable to do so). Essentially, this code uses reflection to check to ...
3 votes
1 answer
163 views

Property validation

I require that the Feature set of my Licence to have a non-empty intersection with a set of features that the module I am ...
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 ...
10 votes
1 answer
1k views

Corrupting Java arithmetic through reflection

Inspired by a PPCG answer, I wrote this code, which shuffles the autoboxing caches of Number subclasses. This leads to, among other things, outputting ...
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 ...
4 votes
1 answer
12k views

Redis Object storage and conversion

I am stepping into a new realm with this project, Reflection. I have written some working code (below) that will potentially store POCO objects in a redis cache (and eventually backed by Table or ...
4 votes
0 answers
2k views

Get n-th data member of a struct

To get n-th member of a struct without non-empty bases and w/o non-public members C++ now have a pretty way: ...
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): ...
4 votes
2 answers
159 views

Java CLI Program Commands

As I was creating a CLI program, I realized having a ton of switch/if-then statements was a messy way to process user input. So, I set up a way to dynamically create commands as I added modules (...
4 votes
1 answer
292 views

Enumerations via reflection in AS3

I'm very much used to enumerations a la Java, where each value in an enum is a distinct object. You can call functions on these objects, and they're generally ...
5 votes
2 answers
2k views

Method/parameter tracer

I am writing a class which can log the activity of an application during run time. The plan is that the SupportMI string will be sent to a DB, from where I can use ...
4 votes
1 answer
197 views

Serializing Objects to Delimited Files Part II

This is a follow up to my previous question: Serializing objects to delimited files I've added some feature enhancements, and based on suggestions from rolfl in chat, I've fixed up a couple ...
1 vote
1 answer
314 views

Decoupled chain of responsibility in Python

I've started to learn Python today. I'm trying to write decoupled middleware or chain of responsibility pattern. In my app I have some two classes: abstract class or interface named Processable ...
2 votes
1 answer
549 views

Unit test code for a private median-of-three function, using reflection [closed]

A Junit test class is used to test the class LibraryCounter. Reflection was used to test the private methods. This made the code much more complicated. ...
7 votes
1 answer
6k views

Serializing objects to delimited files

For a new project I'm going to need to be able to serialize random types to TSV or CSV files, so I write a class which can be used to serialize any object to a TSV, CSV or any other _SV file you can ...
3 votes
2 answers
2k views

Accessing and caching attributes

I have the following manager class that handles access and caching attributes from classes. I am a bit worried about the caching mechanism. Is there a better way of handling it? ...
4 votes
1 answer
2k views

Extended WebBrowser control

I needed the ability to do a few extra things with a WebBrowser control on a .NET Windows Forms Form, and I found it needed some updates. So, I made a few. I added ...
3 votes
1 answer
1k views

Serialize and deserialize n dimensional int array

I've made two symmetric methods which serialize an int array of any number of dimensions into an OutputStream, and read such an array from an InputStream. I was wondering if there is ways this code ...
2 votes
0 answers
875 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 ...
5 votes
3 answers
308 views

Determine if Class B uses Class A ( Java Reflection)

Below is a function that determines if Class B uses Class A. Currently, it tests for: Fields Superclass Constructors Methods ...
0 votes
1 answer
94 views

Business logic parallelization engine

In my Java 8 application there are 3 different classes but each of them contains one similar method, which is dedicated to parallelization of the business logic ...
0 votes
1 answer
5k views

Data model decomposition into key value pairs using reflection and attributes

I'm trying to change how our system generates PDF files. Currently I have a class for each PDF that goes through the model for the PDF and fills in the properties. I want to change that to a self ...
4 votes
1 answer
51 views

Invoking API calls with parameters specified using JSON

I have an instance of a Java class that I need to call some functions on, using the API exposed by another party. For each call, I need to both check for thrown exceptions, and check the value of the ...
10 votes
3 answers
2k views

Tracking Entity Changes (not EF)

So, I kept refactoring my Sage300 API wrapper - I wanted the client code to feel just like using Entity Framework - this is the closest I got to it: ...
7 votes
1 answer
499 views

Milking a COM type library: "fun" with COM reflection

Once upon a time, there was a duck that wanted to know where and how user code was calling into the VBA standard library and Excel object model. To match the rest of its API, the poor little duck had ...
4 votes
2 answers
65 views

Storing disassembled data in a structured way

I want to store the information returned by the dis function of the dis module in a structured way, using a dict, associating the mnemonics of each code of a line to the correspondent line number. ...
2 votes
0 answers
684 views

Pagination links for various lists using Spring-HATEOAS

I'm using Spring HATEOAS to create some links on my REST API. However, the entities i'm returning are very close, so the code to generate the links are the same: ...