reflection

IllegalArgumentException when setting public member

I've been playing around with reflection in Java... and I'm a little bit baffled. I was hoping that the program below would allow me to change the value of a public member variable within a class. However, I receive an IllegalArgumentException. Any ideas? public class ColinTest { public String msg = "fail"; public ColinTest()...

Why is Java's Method class not generic?

That would allow the invoke method to have the right return type. For instance: class Method<T> { T invoke(Object obj, Object... args); } ...

Reflection and Generic type resulting in null

I need to get the type object for IProcessor via reflection and according to documentation I need to do the following: Type.GetType("IProcessor`1[System.Int32]") However, that returns null. I then tried: Type.GetType(typeof(IProcessor<int>).FullName) and still got a null. I am, however, capable of getting the Type argument with: ...

Obfuscation in .NET: how is it done how secure is it?

I brought up a point about obfuscation in another question to which someone replied "obfuscation doesn't stop much". Rather than start a debate in comments on there, I wanted serious community answers as to how safe my code is when obfuscated with X, Y or Z obfuscator, and if any obfuscation tools truly get the job done. I'm also inter...

Find the original implementation of a virtual method

I am trying to use reflection to determine which methods a derived class overrides from a base class. It is fairly easy to determine if the method is not overridden, but trying to determine if a method is overridden in a base class, or simply created as virtual in the derived class is what I am trying to accomplish. So, if Class A has ...

Does Java have an "is kind of class" test method

I have a baseclass, Statement, which several other classes inherit from, named IfStatement, WhereStatement, etc... What is the best way to perform a test in an if statement to determine which sort of Statement class an instance is derived from? ...

Looping over a Python / IronPython Object Methods

What is the proper way to loop over a Python object's methods and call them? Given the object: class SomeTest(): def something1(self): print "something 1" def something2(self): print "something 2" ...

Is there a way to build a new type during Runtime?

I am going to ask a question that might sound weird. Is there a way to build a new class during Runtime? Or at least, add a new property to an existing class. I mean creating a class that doesn't exist and not an instance of an existing class. I could later on use reflections to load and use this class. ...

.NET Assembly Plugin Security

I have used the following code in a number of applications to load .DLL assemblies that expose plugins. However, I previously was always concerned with functionality, rather than security. I am now planning to use this method on a web application that could be used by groups other than me, and I would like to make sure that the securit...

Reflection vs. Attributes in plugin architecture

I am working on an application that loads plugins at startup from a subdirectory, and currently i am doing this by using reflection to iterate over the types of each assembly and to find public classes implementing the IPluginModule interface. Since Reflection involves a performance hit, and i expect that there will be several plugins a...

Can I change a private readonly field in C# using reflection?

I am wondering, since a lot of things can be done using reflection, can I change a private readonly field after the constructor completed its execution? (note: just curiosity) public class Foo { private readonly int bar; public Foo(int num) { bar = num; } public int GetBar() { return bar; } } Foo foo = new Foo(123); Consol...

PropertyInfo.GetValue() - how do you index into a generic parameter using reflection in C#?

This (shortened) code.. for (int i = 0; i < count; i++) { object obj = propertyInfo.GetValue(Tcurrent, new object[] { i }); } .. is throwing a 'TargetParameterCountException : Parameter count mismatch' exception. The underlying type of 'propertyInfo' is a Collection of some T. 'count' is the number of items in the collection. I n...

Cost of Reflection while using factory

Good people of stackoverflow, As always, I am writing a factory in order to dynamically instantiate objects. To schematize, I have four types: class CatDescriptor : PetDescriptor class DogDescriptor : PetDescriptor class Cat : Pet class Dog : Pet I instanciate the two last types from the factory. And here comes the dilemma: Should ...

Java Generics and reflection!

I have a class that looks like this: public class UploadBean { protected UploadBean(Map<String,?> map){ //do nothing. } } To use reflection and create a object by invoking the corresponding constructor, I wrote code as follows: Class<?> parTypes[] = new Class<?>[1]; parTypes[0] = Map.class; Constructor ct = format.g...

Getting static field values of a type using reflection

I've got a set of static "enumeration" classes that I'm using to hold meaningful variable names to represent meaningless code values I receive on an input file. Here's an example of one. Public Class ReasonCodeValue Private Sub New() End Sub Public Shared ReadOnly ServiceNotCovered As String = "SNCV" Public Shared ReadOn...

Getting a delegate from methodinfo

I have a drop down list that is populated by inspecting a classes methods and including those that match a specific signature. The problem is in taken the selected item from the list and getting the delegate to call that method in the class. The first method works, but I cannot figure out part of the second. For example, public...

getMethods(), java

In java, the method 'Class.getMethods()' returns an array of all the methods in the reciever class and also its superclasses. Is there such a method like Class.getMethods() which only give us the class's methods, without those which are inhereted from its superclasses? ...

Visual Studio 2005: Debug C# code from a different project?

I have a desktop application I'm developing with Visual Studio where I need to update a small part of the app on a more frequent basis. To avoid the inconvenience of deploying a new installer every time, I split the more frequently updated support functions into a separate project and compiled it as a DLL. The desktop app now loads this ...

Java reflection: array of classes vs. array of parameter types

I have an object m of class Method. I invoked m.getParameterTypes() to create an array params of the method's parameters. I also have an array arr of Objects. I wanted to check if the objects in arr are of the same types as the types in params (and in the same order). What I did was to create an array classes which includes the class of ...

How can I get System.Type from "System.Drawing.Color" string

I have an xml stored property of some control <Prop Name="ForeColor" Type="System.Drawing.Color" Value="-16777216" /> I want to convert it back as others System.Type type = System.Type.GetType(propertyTypeString); object propertyObj = TypeDescriptor.GetConverter(type).ConvertFromString(propertyValueString); System.Type.GetType("...