Reflection is the process by which a program can observe and modify its own structure and behavior at runtime.
5
votes
1answer
67 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
765 views
Give me thy name, I'll invoke thee
This generic function invokes a property of a given object by name:
...
11
votes
4answers
707 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
43 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
40 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
174 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
93 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 ...
4
votes
3answers
133 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
46 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
118 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
65 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
66 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
52 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
694 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
68 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
95 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
56 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
28 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
146 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
65 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
71 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
77 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
110 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 ...
4
votes
0answers
66 views
Creating companion classes that are `inherited` onto any sub-classes
The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
0
votes
0answers
32 views
Generic Razor view Model property validation for Form
I have run into instances where someone would add columns to a table in the database, update the Entity Framework models for our solution, but forgot to update the forms to compensate for the added ...
3
votes
2answers
248 views
Set Game State from String
Before I used reflection to invoke a state based on the string, it looked like this:
...
1
vote
4answers
180 views
Python Decorator - inspecting function argument values
Some of my functions use a "fail_silently" flag. It is used in the following way:
...
5
votes
2answers
149 views
Recursively merge dictionaries with generic types in C#
I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
1
vote
0answers
957 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):
...
6
votes
1answer
467 views
JSON serializer using generics rather than System.Object
I recently created a custom static class in C# to encode, hopefully, any object it is given (or collection of objects), because I was, at the time, unaware of a native C# library that did the same ...
4
votes
1answer
91 views
Porting a web-based POS system to Android
I'm currently porting a web-based POS system to Android. The Android version uses NavigationDrawer to navigate between menus.
What I need a code review on is my ...
2
votes
3answers
146 views
Property Mapping with Reflection efficiency
I have an object that I am populating via mapping and lookup with Reflection:
...
2
votes
2answers
104 views
config.properties, Static Classes and Reflection
I wanted an opinion about an idea I had regarding the use of config.properties, static classes and the use of reflection.
I have to load some preferences at application startup, for that I will be ...
6
votes
2answers
201 views
Building in the built-in declarations
In order for Rubberduck to be able to "recognize" the built-in VBA functions, procedures and objects, I added yet another constructor parameter to my Declaration ...
10
votes
2answers
514 views
Optimize a generic foreach method that converts Datatable to my object using Reflection
I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
4
votes
2answers
153 views
Type Name or Alias via Reflection for TT Code Generation
I was working on some TT code generation to get rid of mundane C# codings in VS2013 Express Edition, and after researching online, created the following helper methods to facilitate Type declarations.
...
2
votes
1answer
140 views
Implementing transaction method with invoking business methods in a one transaction
Because the ambient transaction isn't supported with informix, I pass the transaction and the connection through my methods.
I ...
1
vote
0answers
72 views
Using interface for generated functions or just create plain functions
I was wondering which code might be better. I'm abstracting away the rote code as follows:
...
5
votes
2answers
721 views
Java MVC model for large scale GUI using annotations
I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts ...
5
votes
3answers
204 views
Avoid static initializer for lists of image and video formats?
I wrote the following code to read constants from annotations:
...
8
votes
2answers
384 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:
...
3
votes
2answers
110 views
Validator part 2
This is a follow up to:
Validating individual properties and whole items
I have a custom class I've written which allows me to validate
individual properties of items, without firing validation ...
2
votes
0answers
44 views
'Tag' packages and make them discoverable
We have another team who is going to expose class packages for use to scan and pickup details from. If they should add some new packages or rename old ones I don't want to have to recode a thing. I am ...
2
votes
2answers
95 views
Function caller (to multiple receivers) interface
This class is designed to call a similar function of multiple objects of multiple classes using a single interface (it is not for calling functions that return a value).
A potential usage will be ...
6
votes
2answers
13k views
Check if any of class properties is not null/empty/was assigned
I have a class that I use to display on a web page fieldset. However, all of the properties of this class are optionally filled in by the user, which means all of them could be null/default. In this ...
4
votes
2answers
93 views
Reflection and Project Euler
I have made a Project Euler runner in order to facilitate the running of the various problems. I have never used reflection before, and I believe that I have found a good use for reflection within ...
5
votes
1answer
131 views
Autowiring publishers/listeners with reflection in Unity Framework
I'm currently building an application with the Microsoft Unity Framework. I also use a simple system of message publishers/listeners inspired from MVVM light and caliburn:
The listener interface
...
5
votes
2answers
372 views
Loading data into a number of different typed List<T>s: Can I do without reflection?
I'm not sure whether my distaste for reflection is justified or not, but it feels ucky that I'm using reflection here.
I'm trying to make a very simple class which has a number of ...
5
votes
2answers
295 views
Evaluating algebra expression using an auxiliary VB class compiled on the fly and consumed in a C# project
I want to create algebra evaluator but I don't want to write my own parser because it takes much time to learn.
I don't like algebra expression in C# because it does not look natural compared to VB ...
5
votes
2answers
4k views
Transform DataReader to List<T> using reflections
I have implemented the code to convert datareader to list of objects. My intention was to not to use column name string literals while reading the datareader.
...