reflection

Trying to load an app through reflection and get error "Could not load file or assembly...The system cannot find the file specified."

The assembly it's trying to find isn't the root assembly - it's a referenced one, but it's in the same folder, and Directory.GetCurrentDirectory() is the folder with all of the files in. I'm stuck - any suggestions? ...

[C#] Is there a way to load a class file to assembly in runtime?

I'm trying to do something that gets a cs file in runtime from user make it meaningful to assembly get its properties, methods etc. Is there a way to do this by reflection in C#? ...

C# Reflection Indexed Properties

I am writing a Clone method using reflection. How do I detect that a property is an indexed property using reflection? For example: public string[] Items { get; set; } My method so far: public static T Clone<T>(T from, List<string> propertiesToIgnore) where T : new() { T to = new T(); Type myType = from...

Get type of generic argument from the stackframe

We are supposed to instantiate our entities through a factory since they are set up differently on the client and server. I want to make sure this is the case but cant quite get it to work. public interface IEntityFactory { TEntity Create<TEntity>() where TEntity : new(); } public abstract class Entity { protected Entity() ...

Determine if a reflected type can be cast to another reflected type

In .net (C#), If you have two types discovered through reflection is it possible to determine if one can be cast to the other? (implicit and/or explicit). What I'm trying to do is create a library that allows users to specify that a property on one type is mapped to a property on another type. Everything is fine if the two properties ha...

Getting the property name that a value came from

I would like to know how to get the name of the property that a method parameter value came from. The code snippet below shows what I want to do: Person peep = new Person(); Dictionary<object, string> mapping = new Dictionary<object, string>(); mapping[peep.FirstName] = "Name"; Dictionary<string, string> propertyToStringMapping = Conver...

Reflection - Getting the generic parameters from a System.Type instance

If I have the following code: MyType<int> anInstance = new MyType<int>(); Type type = anInstance.GetType(); How can I find out which type parameter(s) "anInstance" was instantiated with, by looking at the type variable ? Is it possible ? ...

PHP 5 Reflection API performance

I'm currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instanciate controller classes and invoke their methods without any required configuration ("convention over configuration" approach). I'm concerned about performance, even th...

Create an object knowing only the class name?

I have a set of classes, each one is a different strategy to do the same work. namespace BigCorp.SuperApp { public class BaseClass { } public class ClassA : BaseClass { } public class ClassB : BaseClass { } } The choice of which strategy to use is configurable. I want to configure only the class name 'ClassB' instead of t...

How to use reflection to create a "reflection machine"

OK so that title sucks a little but I could not think of anything better (maybe someone else can?). So I have a few questions around a subject here. What I want to do is create a program that can take an object and use reflection to list all its properties, methods, constructors etc. I can then manipulate these objects at runtime to tes...

C# Reflection to Identify Extension Methods

In C# is there a technique using reflection to determine if a method has been added to a class as an extension method? Given an extension method such as the one shown below is it possible to determine that Reverse() has been added to the string class? public static class StringExtensions { public static string Reverse(this string v...

Instantiating object of type parameter

I have got a template class as follows: class MyClass<T> { T field; public void myMethod() { field = new T(); // gives compiler error } } How do I create a new instance of T in my class? ...

Difference between ComponentModel reflection (e.g PropertyDescriptor) and standard reflection (e.g PropertyInfo)?

There is a distinct overlap between what u can do with both of them. Is the ComponentModel reflection stuff just a little friendlier layer on top of System.Reflection? ...

How do you find only properties that have both a getter and setter?

C#, .NET 3.5 I am trying to get all of the properties of an object that have BOTH a getter and a setter for the instance. The code I thought should work is PropertyInfo[] infos = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.GetProperty); However, the results in...

How do I get all instances of all loaded types that implement a given interface?

We need to get all the instances of objects that implement a given interface - can we do that, and if so how? ...

Problems finding an attribute attached to a Type

When running the below code a type is never returned, despite there being a class with the correct attribute assigned. In fact the attr array always has a length of 0. Assembly a = Assembly.LoadFile(file); foreach (Type t in a.GetTypes()) { object[] attr = t.GetCustomAttributes(typeof(SchemeNameAttribute), false); foreach (obje...

C# Assembly.Load vs Assembly.ReflectionOnlyLoad

Hi all, I'm trying to understand the differences between Assembly.Load and Assembly.ReflectionOnlyLoad. In the code below I am attempting to find all of the objects in a given assembly that inherit from a given interface: var myTypes = new List<Type>(); var assembly = Assembly.Load("MyProject.Components"); foreach (var type in asse...

In Python, how can you get the name of a member function's class?

I have a function that takes another function as a parameter. If the function is a member of a class, I need to find the name of that class. E.g. def analyser(testFunc): print testFunc.__name__, 'belongs to the class, ... I thought testFunc.__class__ would solve my problems, but that just tells me that testFunc is a function....

Python decorator makes function forget that it belongs to a class

I am trying to write a decorator to do logging: def logger(myFunc): def new(*args, **keyargs): print 'Entering %s.%s' % (myFunc.im_class.__name__, myFunc.__name__) return myFunc(*args, **keyargs) return new class C(object): @logger def f(): pass C().f() I would like this to print: Entering C...

I need help with this error: java.lang.NoSuchMethodError...

I have this Java code (JPA): String queryString = "SELECT b , sum(v.votedPoints) as votedPoint " + " FROM Bookmarks b " + " LEFT OUTER JOIN Votes v " + " on (v.organizationId = b.organizationId) " + "WHERE b.userId = 101 " + ...