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...
How do I find the length of a multi-dimensional array with reflection on java?
...
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...
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
{
...
I'm getting this error when I try to serialize a Method object.
java.io.NotSerializableException: java.lang.reflect.Method
Any Idea?
...
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...
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 {...
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?
...
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 ...
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...
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...
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...
Class c = List<Foo>.class
doesn't seem to work.
...
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 ...
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...
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...
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
{
...
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...
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...
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 ...