reflection

Handling Type.InvokeMember Inner Exceptions nicely

I have a bit of code which is calling the InvokeMember method on a Type. This is fine and works however if an exception occurs within the member being invoked then the debug jumps to where I am calling InvokeMember as opposed to the inner exception. Is it possible to get around this so that the code debugs as expected? ...

PHP Method Chains - Reflecting?

Is it possible to reflect upon a chain of method calls to determine at what point you are in the chain of calls? At the very least, is it possible to discern whether a method is the last call in the chain? $instance->method1()->method2()->method3()->method4() Is it possible to do the same using properties that return instances of obje...

How would you explain reflection to a non-programmer?

I have a friend who is interested in getting into programming and is asking about a lot of different concepts. Classes, interfaces and things like polymorphism / inheritence have been easy to explain, but I'm struggling a bit with analogies for reflection. How would you explain what it is and how it works in practice? ...

C# determine a Nullable property DateTime type when using reflection

Hi, I have a question on how to determine an object's Nullable property type. ObjectA with a property DateTime? CreateDate; when i am iterate through it's properties like the following code, how do I check if a property is a Nullable DateTime type? thanks foreach (PropertyInfo pi in ObjectA.GetType().GetProperties()) { ...

Function pointers in C#

I suppose in some ways either (or both) Delegate or MethodInfo qualify for this title. However, neither provide the syntactic niceness that I'm looking for. So, in short, Is there some way that I can write the following: FunctionPointer foo = // whatever, create the function pointer using mechanisms foo(); I can't use a solid delegate...

How do I find all the methods that have specific parameters with reflection?

I need to find all the methods in a class that accept a set of parameters in a specific order, some of them are generics (Collection). The example on the Sun web site only works with non generic classes: http://java.sun.com/docs/books/tutorial/reflect/member/methodInvocation.html cheers in advance ...

Java Beans: Overglorified Associative Arrays?

I don't understand the nature of Java Beans that well. Well, at least how I see them used in some code-bases that pass through our shop. I found this question: http://stackoverflow.com/questions/315142/java-beans-what-am-i-missing The accepted answer there makes it look like programmers tend to abuse Java Bean (which I really don't do...

java: easiest way to populate a bean using servlet params

without using any big web framework (just servlets), do you know a ready to use small library that can populate my bean properties from the params of an http request? ...

as3 object serialization (to as3 code)

Hello what i'm trying to do is walk an object that is also a complex tree of objects and output the actionscript 3 code it took (or takes) to create instantiate and populate that object and all its children. so for instance if you saw something like this in your debugger myObjectToParse (ParseMe@173e239) ----------[0]someBlob (SomeBlo...

How do you get the fully qualified method name when an exception happens

Hello, I have a global HandledExceptionHandler. In the catch part of my try catch block I would like to pass the fully qualifed method name where the exception occurred. How do you do that? Can it be done without reflection. HEre is an example of what I am looking for... Public Sub MySub Try 'some error happens Catch ...

How to detect if a Type is a generated DynamicProxy without referencing Castle DynamicProxy?

I am using castle DynamicProxy and was wondering if there is a way of detecting if a Type is a proxy without referencing Castle DynamicProxy? So while I am using Castle DynamicProxy as an example I would like code that would work for any in memory generated type. var generator = new ProxyGenerator(); var classProxy = generator.Create...

How do I read a private field in Java?

I have a poorly designed class in a 3rd-party JAR and I need to access one of its private fields. For example, class IWasDesignedPoorly { private Hashtable stuffIWant; } IWasDesignedPoorly obj = ...; How can I use reflection to get the value of stuffIWant? ...

Automatic translation of C# enum to JavaScript

I have a flags enumeration in a .NET assembly that is getting called from an ASP.NET page. I want to have a Visual Studio build step generate a .js file that has the JavaScript equivalent in it. Are there any tools for doing this? edit: This seems to work. public class JavaScriptReflection { public static string Go(Type type) ...

Get property value from string using reflection in c#

I trying implement in my code this example link but in private object GetSourceValue(string propertyName) {} he have a switch comparing various types. I want remove this types and properties and have a only GetSourceValue does can get source of property using only a string in parameter. I want pass class and property in string e ...

C# Using Reflection to copy base class properties

I would like to update all properties from MyObject to another using Reflection. The problem I am coming into is that the particular object is inherited from a base class and those base class property values are not updated. The below code copies over top level property values. public void Update(MyObject o) { MyObject copyObject =...

Instancing a class with an internal constructor

I have a class whose constructor is defined as internal, which means I cannot instantiate it. While that may make sense, I would still like to do it once for debugging and research purposes. Is it possible to do so with Reflection? I know I can access Private/Internal Members, but can I call an internal constructor? Or, as the construc...

Convert C# Array to String Using Reflection / Type Conversion

I am trying to figure out how to convert an arbitrary array or collection to a string via reflection and it's driving me nuts..NUTS...I'm about yay close to putting my red swingline through the computer monitor here. So for example, given an array of Color objects, I want the default string representation of that array (you know, semico...

How do I compare types when using generics?

I am trying to derive the type of an object at runtime. Specifically I need to know two things whether it implements ICollection or IDto. Currently my only solution I have been able to find is this: private static bool IsACollection(PropertyDescriptor descriptor) { bool isCollection = false; foreach (Type type ...

Is using reflection a design smell?

I see a lot of C#, .net questions solved here using reflection. To me, a lot of them look like bending the rules at the cost of good design (OOP). Many of the solutions look unmaintenable and "scripty". Is using reflection a good practice in general? Are there things that can only be solved by reflection? edit: Please give examples wh...

Cache Reflection Results (Class Properties)

Hello, considering that fairly static data should not be re-evaluated but cached instead, I wondered if it is possible to use Reflection to obtain class properties once, and then cache them so that I could dynamically evaluate object properties and read/assign values, but not have the Reflection overhead every time I do that. Is this po...