reflection

Call method of the derived class through reflection. Possible or no?

Hi! I have a follwing class structure: public abstract class AbstractFoo { public virtual void Prepare() { } } public class Foo : AbstractFoo { public override void Prepare() { } } public class Bar : Foo { public override void Prepare() { } } public class ClassThatUses { public Foo Foo; } var...

Multi-Dimension length array reflection java

How do I find the length of a multi-dimensional array with reflection on java? ...

Java reflection: What does my Collection contain?

Hi guys, I've defined a method in a class: public void setCollection(Collection<MyClass>); and in another class public void setCollection(Collection<OtherClass>); (and really, lots of similar classes) All are in classes with the same superclass, and I have a method in a support-class where I want to call this method and set it wit...

Dynamically implement interface in Groovy using invokeMethod

Groovy offers some really neat language features for dealing with and implementing Java interfaces, but I seem kind of stuck. I want to dynamically implement an Interface on a Groovy class and intercept all method calls on that interface using GroovyInterceptable.invokeMethod. Here what I tried so far: public interface TestInterface { ...

Serialization of Method object in Java is possible?

I'm getting this error when I try to serialize a Method object. java.io.NotSerializableException: java.lang.reflect.Method Any Idea? ...

Determine if reflected property can be assigned null

I wish to automagically discover some information on a provided class to do something akin to form entry. Specifically I am using reflection to return a PropertyInfo value for each property. I can read or write values to each property from my "form", but if the property is defined as "int", I would not be able to, and my program should n...

Accessing private variables in Java via reflection

I'm trying to write a method that will get a private field in a class using reflection. Here's my class (simplified for this example): public class SomeClass { private int myField; public SomeClass() { myField = 42; } public static Object getInstanceField(Object instance, String fieldName) throws Throwable {...

How to find function parameters

I need to log all the function parameters in a dozen functions. Is there a way to pro grammatically determine all the parameters and their values (or at least their .ToString() value)? Perhaps via reflection? ...

Java static reflection on subclasses

Hi all. I am implementing a sort of ORM in Java. I am trying to do a static find method that is only in the parent class. Let me get to the point: public class DB { public static Object find (int id) { // i want to return anew instance of the calling subclass } } public class Item extends DB { // nothing here } public class ...

How to get the properties of a class using reflection (specifying how many levels of heirarchy) in C#.Net?

So for example: class GrandParent { public int GrandProperty1 { get; set; } public int GrandProperty2 { get; set; } } class Parent : GrandParent { public int ParentProperty1 { get; set; } public int ParentProperty2 { get; set; } protected int ParentPropertyProtected1 { get; set; } } class Child : Parent { publi...

Deeply cloned Panel; controls don't redraw

Hello. I have problems with redrawing child controls of cloned panel. First, I'm not using IClonable. I'm using reflection. My code: public static Panel ClonePanel(Panel panel) { Panel newPanel = (Panel) CloneControl(panel); foreach (Control ctl in panel.Controls) { Control newCtl = CloneControl(ctl); newC...

.NET Reflection set private property

If you have a property defined like this: private DateTime modifiedOn; public DateTime ModifiedOn { get { return modifiedOn; } } How do you set it to a certain value with Reflection? I've tried both: dto.GetType().GetProperty("ModifiedOn").SetValue(dto, modifiedOn, null); and dto.GetType().GetProperty("modifiedOn").SetValue(d...

What is the Class Of List<Foo> in Java?

Class c = List<Foo>.class doesn't seem to work. ...

Java: Getting the properties of a class to construct a string representation

Let's say I have a class like this (and also further assume that all the private variables: public class Item { private String _id = null; private String _name = null; private String _description = null; ... } Now, if I want to build a toString() representation of this class, I would do something like this inside ...

With Java reflection how to instantiate a new object, then call a method on it?

Hi, I'm pretty new to Java, and I'm facing a reflection issue. Let's say i have to dynamically call the method fooMethod on an instance of the class Foobar I got so far an instance of Foobar with: Object instance = Class.forName("Foobar").newInstance(); Let's say I know there's a method fooMethod on this object (I can even check t...

How to get .NET array type from the string "string[]"?

Given the string "string[]" and asked to get the underlying Type for this class, one might start with: private Type getTypeByName(string typeName) { if (typeName.EndsWith("[]")) { return something; // But what? } return Type.GetType(typeName); } What type is "string[]" and how does one reflect the type out...

Why is the members of an inherited interface not available using reflection ?

When reflecting on an interface type, I only get the members of the specific type, not inherited members. In this over-simplified example, the program only prints "Name", not "ItemNumber", "Name" as I would expect: using System; public interface IBasicItem { string ItemNumber { get; set; } } public interface IItem : IBasicItem { ...

How to get the type of an array-property?

I have something like this: public class Foo { public Bar[] Bars{get; set;} } public class Bar { public string Name{ get; set; } } I start reflecting: PropertyInfo propertyInfo = typeof(Foo).GetProperty("Bars"); so far so good. I want to reflect deeper: Type type = _propertyInfo .PropertyType; // this gives me that the t...

Set Nested Property Values using Reflections

I've searched throughout but can't find the exact answer to my question. Take for instance the following code: public class Company { private string m_strName; private Customer m_objCustomer; public Company() { m_strName = ""; m_objCustomer = new Customer(); } public string Name { get { retur...

How can I read the documentation from a class in another class?

Hi all. let's say I have class A and class B. Class A's definition is: /// <summary> /// This is the class documentation. /// </summary> public class A { /// <summary> /// This is the documentation for attribute. /// </summary> public int attribute; ... } I want to access the documentation from class A (ie. those ...