Say I have a base class TestBase where I define a vistual method TestMe()
class TestBase
{
public virtual bool TestMe() { }
}
Now I inherit this class:
class Test1 : TestBase
{
public override bool TestMe() {}
}
Now, using Reflection, I need to find if the method TestMe has been overriden in child class - is it possible?
...
I would like to get gain access to the type of Object held in a Collection. Below is a simplified example of when and why I might want to do this. Is this even possible?
List<Address> addressList = new LinkedList<Address>();
Main.addElement(addressList);
Class Main{
public void addElement(Object inArgument){
List<Object> ar...
UPDATE: The suggestion to use an expression tree to construct a lambda using the given MethodInfo, in conjunction with the Expression<TDelegate>.Compile method, proved to be a gold mine in my scenario. In the specific case where I was toying with this idea, I saw average execution time for a particular method go from ~0.25 ms to ~0.001 m...
Hi guys,
I'm tring to create a generic collection of dynamic type at runtime of Silverlight application. My code:
Type listType =
Type.GetType("System.Collections.ObjectModel.ObservableCollection`1[["
+ type.AssemblyQualifiedName +
"]], System.Windows, Version=2.0.5.0, Culture=neutral,
PublicK...
What I'd like is for this class
class Car {
public function __construct(Engine $engine, Make $make, Model $model)
{
// stuff
}
}
Get an array that has the types needed to construct this car (Engine, Make, Model) in the order they are needed for the constructor. I'm using this for a Dependency Injection-esque thin...
[<ReflectedDefinition>]
let rec x = (fun() -> x + "abc") ()
The sample code with the recursive value above produces the following F# compiler error:
error FS0432: [<ReflectedDefinition>] terms cannot contain uses of the prefix splice operator '%'
I can't see any slicing operator usage in the code above, looks like a bug... :)
Lo...
Hey there!
I'm setting public fields of the Object 'this' via reflection. Both the field name and the value are given as String. I use several various field types: Boolean, Integer, Float, Double, an own enum, and a String. It works with all of them except with a String. The exception that gets thrown is that no method with the Signatur...
I'm having trouble with doubling up on my code for no reason other than my own lack of ability to do it more efficiently...
for (Method curr: all){
if (curr.isAnnotationPresent(anno)){
if (anno == Pre.class){
for (String str : curr.getAnnotation(Pre.class).value()){
if (str.equals(...
I have
Class<? extends Object> class1 = obj.getClass();
Field[] fields = class1.getDeclaredFields();
for (Field aField : fields) {
aField.setAccessible(true);
if (aField.getType().isArray()) {
for (?? vals : aField) {
System.out.println(vals);
}
}
}
...
Where can I download source code for the .NET Framework? I mean sources of libraries. I need the source for reflection methods like invoke and other.
...
I have a string like a=6&id=99 (i might store it in html as 'a=6&id=99' however thats not what js will see). I would like to convert that string into an object so i can do func(o.a); or o.id=44; How do i do that?
Part 2: How do i convert that object back to a query string? it would probably be trivial code that i can write.
...
I would like to be able to call a function based on its name provided by a string. Something like
public void callByName(String funcName){
this.(funcName)();
}
I have searched a bit into lambda funcions but they are not supported. I was thinking about going for Reflection, but I am a bit new to programming, so I am not so familiar ...
Is it possible to get the class type from inside the static initialization block?
This is a simplified version of what I currently have::
class Person extends SuperClass {
String firstName;
static{
// This function is on the "SuperClass":
// I'd for this function to be able to get "Person.class" without me
//...
I use
if (clazz.getSuperclass().getName() == "java.lang.Object")
Is there a better way?
...
Right now I have
private static void getMethods(Class<? extends Object> clazz) {
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method aMethod : declaredMethods) {
aMethod.setAccessible(true);
// Print the declaration
System.out.print(Modifier.toString(aMethod.getModifiers()) + " "
+ aMe...
I have the class name stored in a property file. I know that the classes store will implement IDynamicLoad. How do I instantiate the class dynamically?
Right now I have
Properties foo = new Properties();
foo.load(new FileInputStream(new File("ClassName.properties")));
String class_name = foo.getProperty("class","DefaultCla...
I have a class
class a
{
private Dictionary <int , string> m_Dict = new Dictionary<int , string>();
}
from some other component/class need to add values to the m_Dict dictionary using reflection! How do i do it ? i searched and tried but was not successfull.
...
Hi,
I have been trying to use reflection for a specifiec Field in the android.os.build class, the MANUFACTURER field...
I have tried by using this code :
try
{
Class myBuildClass = android.os.Build.class;
Field m1 = Build.class.getDeclaredField("MANUFACTURER");
validField = true;
manufacturer = Build...
I need to find a way of taking a hibernate object and discovering at runtime all of the getter methods that relate to persistable fields. I'm using annotations in the classes but have previously had difficulties working with them (I ran into a 2 year old bug the java developers still haven't fixed).
Does anyone know how I can do this pl...
I want to generate .net code from a template so that it more rapid, so lazy developers (and I mean that in the nicest possible way!) don't have to write them in the IDE, compile them, etc...
I know I can roll my own tool which generates the code using reflection (by reading in some text file, etc), but I just wondered if there was an ea...