reflection

How can I enumerate methods that have MethodAttributes.PrivateScope using Reflection?

How can I enumerate methods that have MethodAttributes.PrivateScope using Reflection? ...

Why is there no way to do introspection in Objective C with Objects?

I have seen examples (on here especially) of calling hideous C functions and getting structures back that have to be iterated, replete with reams of underbars. Why can't I do this (pseudo to follow): Money *cost = [[Money alloc] init]; for (Property *property in [[cost class] properties]){ .. } for (Method *method in [[c...

Accessing the constructor by using Reflection

Assume the class is public and and the constructor is internal like as Public class A { private string text; internal A(string submittedText); public string StrText { get; } } In this case how could I Access the constructor by using Reflection. What I have done so far Type[] pTypes = new Type[1]; pTypes[0] = typeof(obj...

IL short-form instructions aren't short?

Hi. I was looking at the IL code of a valid method with Reflector and I've run into this: L_00a5: leave.s L_0103 Instructions with the suffix .s are supposed to take an int8 operand, and sure enough this should be the case with Leave_S as well. However, 0x0103 is 259, which exceeds the capacity of an int8. The method somehow works, bu...

Reflect on a dynamic type to tell if it was a dynamic type, to begin with

Is there a way that one can tell if the type that an object was assigned to, was a dynamic type? For example: dynamic foo = GetCat(); Console.WriteLine( (foo is Cat).ToString() ); // will print True because // at the execution time, foo will have assumed the Cat type. However, is // there a mechanism by which I can reflect on foo and ...

Programmatically implementing an interface that combines some instances of the same interface in various specified ways

What is the best way to implement an interface that combines some instances of the same interface in various specified ways? I need to do this for multiple interfaces and I want to minimize the boilerplate and still achieve good efficiency, because I need this for a critical production system. Here is a sketch of the problem. Abstractl...

Creating DescriptionAttribute on Enumeration Field using System.Reflection.Emit

I have a list of strings which are candidates for Enumerations values. They are Don't send diffs 500 lines 1000 lines 5000 lines Send entire diff The problem is that spaces, special characters are not a part of identifiers and even cannot start with a number, so I would be sanitizing these values to only chars, numbers and _ To keep...

Reflection, invoke

I have a dll file, and I took an object from it and called the functions inside this dll by the object, like this: Command testClass = (Command)assembly.CreateInstance(creatObject); testClass.Execute(); I used reflection for some reason. So I need to use invoke function & set values for variables, then calling the basi...

Dynamic access of classes of a given namespace

Hi! I'm writing an interface that will be implemented by a lot of classes, and I'm writing a class that will hold a collection of instances of these implementations. Every class will have a default constructor. So, is there a simple way (e.g. using some kind of reflection) to put an instance of each of these implementing classes to the...

Convert Null Value to String - C#.NET

foreach (PropertyInfo PropertyItem in this.GetType().GetProperties()) { PropertyItem.SetValue(this, objDataTable.Rows[0][PropertyItem.Name.ToString()], null); } In one of the loops i get this exceptional error: Object of type 'System.DBNull' cannot be converted to type 'System.String'. The error occurs because one...

Getting default value for java primitive types

I have a java primitive type at hand: Class c = int.class; // or long.class, or boolean.class I'd like to get a 'default value' for this class - specifically the value is assigned to fields of this type if they are not initialized. E.g., '0' for a number, 'false' for a boolean. Is there a generic way to do this? I tried c.newInstanc...

Class<T> and static method Class.forName() drive me crazy.

Hi, this code doesn't compile. I'm wondering what I am doing wrong: private static Importable getRightInstance(String s) throws Exception { Class<Importable> c = Class.forName(s); Importable i = c.newInstance(); return i; } where Importable is an interface and the string s is the name of an implementing class. The compiler says: ....

is there any way to access all references to given object?

Hello anyone has idea if and how is it possible to destroy / change php object which is referenced in many places? unset obviously destroys only one reference, and sometimes tracing all references manually is not an option. Any ideas? Maybe there is something i am missing in Reflection ? ...

Problem with dynamically loading assemblies in .NET

We've built a small component which takes an Id, looks up an entry in the database for an assembly/namespace/class, and dynamically loads an instance of the class that we're after. It has been working fine up until now, but when running this code in VS 2010, it's failing. Private Function AssemblyLoaded(ByVal assemblyFile As String) As ...

How do I put all types implementing a certain generic interface in a dictionary?

Given a particular interface ITarget<T> and a particular type myType, here's how you would determine T if myType implements ITarget<T>. (This code snippet is taken from the answer to an earlier question.) foreach (var i in myType.GetInterfaces ()) if (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ITarget<>)) ...

Loading assemblies dynamically‏ AssemblyResolve issue

Note: This is a continuation of my previous post: Complicated API issue with calling assemblies dynamically‏ I'm writing a .Net windows forms application that runs on a network and uses an SQL Server to save and pull data. I want to offer a mini "plugin" API, where developers can build their own assemblies and implement a specific in...

Working with libpath with java reflection.

I'm dynamically loading a class and calling a method on it. This class does JNI. When I call the class, java attempts to load the library. This causes an error because the library is not on the libpath. I'm calling from instead a jar so I can't easily change the libpath (especially since the library is not in the same directory or a ...

How to make Spring accept fluent (non-void) setters?

Hi, I have an API which I am turning into an internal DSL. As such, most methods in my PoJos return a reference to this so that I can chain methods together declaratively as such (syntactic sugar). myComponent .setID("MyId") .setProperty("One") .setProperty2("Two") .setAssociation(anotherComponent) .execute(); My ...

Statically checking a Java app for link errors

I have a scenario where I have code written against version 1 of a library but I want to ship version 2 of the library instead. The code has shipped and is therefore not changeable. I'm concerned that it might try to access classes or members of the library that existed in v1 but have been removed in v2. I figured it would be possible t...

How can I filter FieldInfos that are the underlying implementation of a class event ?

I want to get all the fields of a class without getting the underlying implementations of the class event. type.GetFields(BindingFlags...) returns the nuderlying delegate for event fields. Does anyone knows how to filter them out ? ...