Reflection is the process by which a program can observe and modify its own structure and behavior at runtime.

learn more… | top users | synonyms

2
votes
1answer
56 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. ...
5
votes
2answers
99 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 ...
1
vote
1answer
119 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: <...
3
votes
2answers
89 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? ...
3
votes
1answer
45 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 ...
3
votes
1answer
86 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 ...
0
votes
1answer
82 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 ...
3
votes
1answer
124 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 ...
5
votes
3answers
209 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 ...
6
votes
2answers
367 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 ...
0
votes
1answer
100 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
1answer
29 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 ...
8
votes
1answer
94 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
1answer
130 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
2answers
47 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
1answer
36 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 loading contains. I expect other lists in my License to form similar ...
2
votes
0answers
61 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: ...
10
votes
3answers
250 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: ...
1
vote
0answers
100 views

Saving the state of a ViewModel

I've the following scenario, I've got some viewmodel that need to persist their state on disk. I've defined a custom attribute as: ...
2
votes
3answers
172 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: ...
8
votes
1answer
113 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... ...
3
votes
1answer
78 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 ...
6
votes
1answer
52 views

Wrapping the Sage300 View API with… a Repository

Related: Something like a LINQ provider I needed to work with the Sage300 View API. I had never worked with it, but my first impression has been that the API is ...
3
votes
1answer
57 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. ...
4
votes
1answer
62 views

Request handler based solely on reflections

The code itself is divided into 3 logical parts: Core modules (I call them Kernel modules, my love for Linux) - those are basic modules a web-developer would need, e.g. database wrapper class (PDO), ...
12
votes
2answers
729 views

Extension method to list enum values

I have the following enum extension method: ...
6
votes
1answer
91 views

NullGuard for throwing more informative exceptions

This small utility class is my solution for a more convenient way for checking against null. I also wanted to have more informative NullReferenceExceptions but I ...
5
votes
1answer
101 views

How to refactor this mapping class not to violate SOLID

So I have the below (which is working correctly and all my unit tests are passing) but it's ugly and is violating SOLID, I will have to change the class every time I want to be able to map a different ...
11
votes
3answers
804 views

Give me thy name, I'll invoke thee

This generic function invokes a property of a given object by name: ...
11
votes
4answers
801 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 ...
0
votes
1answer
51 views

Creating instance of all classes that have certain attribut value

I have a simple custom attribute MessageDeliveryAttribute that has one string filed. Also I have several classes that mark with this attribute like: ...
2
votes
1answer
52 views

Looking up alias using inspect in Python

I'm on a quest for making a good debug_print() method for printing out debug information in some of my private projects. When testing I aliased my ...
5
votes
2answers
188 views

“Better” Exception with autogenerated message

Because I don't like writing the same useless exeption messages all the time ;-) I thought I create a better exception that would make this for me. This is what I came up with: ...
6
votes
1answer
104 views

A C function for returning the address of the calling function

Suppose you are given two functions, foo and bar, and neither of them are inlined. Now, if ...
5
votes
3answers
573 views

Generic toString() for JPA base entity class

In a Java/JPA project I usually define a base class (on which I put the id). The goal is to implement an generic toString() on this base class (named BaseEntity) from which all other entities inherit. ...
1
vote
1answer
51 views

Map all symbols in module to dictionary

The div and add functions are located randomly in my package structure. I have a function with this signature: ...
3
votes
2answers
203 views

Getting a list of all fields in an object

I've got the following code that I use to output a list of all (public) fields in an object in an easy(ish) to read way. The issue with it is that the code is not easy to look at, and I'm not sure ...
3
votes
2answers
95 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
2
votes
1answer
263 views

Getting translated string using reflection and Resource Manager

I wrote the following code to get the translated string from Resource Manager. The method GetTranslatedString is called more than 50 times in my project. ...
2
votes
2answers
65 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 ...
10
votes
3answers
887 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. ...
1
vote
1answer
127 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 ...
7
votes
2answers
149 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. ...
2
votes
1answer
127 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 ...
2
votes
1answer
35 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: ...
4
votes
2answers
956 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 ...
5
votes
1answer
79 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. ...
6
votes
1answer
147 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? ...
5
votes
1answer
85 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 ...
6
votes
1answer
153 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 ...