In C#, is there a way (terser the better) to resolve the name of a parameter at runtime?
For example, in the following method, if you renamed the method parameter, you'd also have to remember to update the string literal passed to ArgumentNullException.
public void Woof(object resource)
{
if (resource == null)
{...
What are your best examples of using Reflection in production code?
...
Given two objected that do not contain reference loops within them, do you know a method that tests their equality in a "generic" way (through reflection)?
I basically want the same semantics as struct equivalence, only on classes.
...
I'm writing a testing Framework which is starting a GUI Application. To be able to test this GUI in the case of an SWT application I need to know it's display. In general, this display is loaded by another classloader, therefore I'm using the method findDisplay(Thread t) of the swt Display class by reflection to accomplish this task. My ...
I have a Java project that needs a "addon" interface. I was thinking about loading some kind of class files having default methods like initialize() and shutdown() that will be called after the class has been loaded into the application. Is this the way to do it? How would I approach this problem?
...
I have a class that uses XML and reflection to return Objects to another class.
Normally these objects are sub fields of an external object, but occasionally its something I want to generate on the fly. I've tried something like this but to no avail. I believe that's because JAVA won't allow you to access private methods for reflection....
I'm going to develop a Firefox extension which uses some Java classes.
The extension gets the value of <input type="file"> fields, using Javascript.
The Java class I'm going to create is the following:
public class Firefox {
public static String inFileName;
public static void main(String[] args) throws IOException {
in...
I've got a data provider that contains a collection of entities. I only want to be able to create a new entity through the data provider.
I.e, to create a new record I need to use:
Entity entity = Provider.AddNew();
enity.set_Properties... etc
My issue is that if I set my entities to Internal, System.Activator cannot create an Instan...
Possible Duplicates:
What is reflection, and why is it useful?
So I've read the Reflection tutorial on Java's website, and I think I generally understand that it allows a class to inspect itself, having access to properties, methods, etc. However, how, if at all, does this relate to mutable or immutable code? Can classes change ...
Given a null cast:
var result = MyMethod( (Foo) null );
Is it possible to use this extra information inside the method with reflection?
EDIT:
The method's signature is something like:
object MyMethod( params object[] args )
{
// here I would like to see that args[0] is (was) of type Foo
}
...
When using reflection it is possible to obtain the call stack (apart from that it can be a crude approximation due to JIT optimizations) using System.Diagnostics.StackTrace and examine the StackFrame objects contained.
How can I get a reference to the object (the this-pointer) on which a method in a stack frame is executing?
I know I c...
This is the same Question as one I asked earlier BUT that one was in reference to normal C#.
This is Silverlight 2, and I don't have ICustomTypeDescriptor
So here is the question again:
I have, say a few switch panels (for those that like analogies).
Each of these switch panels has switches that have a Name(string) can be in state(bool...
I'm trying to understand Java reflecton and am encountering difficulties when working with non-Integer setter methods.
As an example, how can I resolve the "getDeclaredMethod()" call below?
import java.lang.reflect.*;
class Target {
String value;
public Target() { this.value = new String("."); }
public void setValue(Strin...
Gday All,
I have been dabbling in some F# of late and I came up with the following string builder that I ported from some C# code. It converts an object into a string provided it passes a Regex defined in the attributes. Its probably overkill for the task at hand but its for learning purposes.
Currently the BuildString member uses a mu...
I posted a question last night about Java Reflection and am discovering compiler warnings this morning.
C:\javasandbox\reflection>javac ReflectionTest.java
Note: ReflectionTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\javasandbox\reflection>javac -Xlint:unchecked ReflectionTest.jav...
How can I convert TO a Nullable from a String using reflection?
I have the following code to convert TO almost any value type given almost any value. There is quite a bit of code above this to use the IsAssignableFrom, etc. so this is the last resort.
MethodInfo parse = t.GetMethod("Parse", new Type[] { typeof(string) });
if (parse ...
I am creating a type converter for use in a in-house library that should be able to convert from any type returned by a database (long, DBNull, bool, string, etc...) to any compatible type.
This all works fin and dandy for items that can either be casted:
try { return (T)value } catch(InvalidCaseException) { }
Or can be parsed:
see ...
Hi, I'm trying to load a java .class file dynamically and call it by reflection.
I've got a class called Foo; it has an empty constructor and has one method called doit() which takes a String argument and returns a String. Also it reverses the String.
Here is my code:
URL url = new URL("file://C:/jtest/");
URLClassLoader loader = ne...
I am trying to find information on using reflection within a MSBuild task.
I need a way of iterating through the methods of a class contained with a website, at build time. Is this possible? Is MSBuild the best tool to use? Is this an unreasonable requirement, I can't seem to find any documentation on the subject?
Any help would be muc...
I have a DataContract class that I have to fill by values from the Active Directory of our company.
[DataContract(Namespace = Global.Namespace)]
public class UserProfile
{
[DataMember(IsRequired = true, EmitDefaultValue = false)]
public string EmployeeID { get; private set; }
[DataMember(IsRequired = true, EmitDefaultValue ...