reflection

ExpressionTree - GetSetMethod Error: Method 'System.String get_Name()' is not defined for type 'System.String'

Here is my method: public static MethodCallExpression ClonePropertyAssignmentLambda<T>(Expression source, string property) { var targetExp = Expression.Parameter(typeof (T), "target"); var propertyInfo = typeof (T).GetProperty(property); var targetProperty = Expression.Property(targetExp, propertyInfo); ...

Get public fields?

I've got a struct defined like this private struct Combinators { public const char DirectChild = '>'; public const char NextAdjacent = '+'; public const char NextSiblings = '~'; public const char Descendant = ' '; } I want to use reflection to get a list of all the values of the public const char fields in the struct (...

Get class type?

Given public class A { public static void Foo() { // get typeof(B) } } public class B : A { } Is it possible for B.Foo() to get typeof(B) in .NET 4? Note that Foo is static. ...

Get specific property of object using java Reflection

I have class User which have different objects like country,address,car and many others. All embedded objects have userid property which is long. I have User object, i want to set userid property of all embedded objects to specific value or null using java reflection. Otherwise i have to write methods for each different object. ...

C# Equivalent of PHP Dynamic Method Calling

In PHP, I can try to call any method that might exist on an object like this: $object->{$method}(); Where $object is our PHP Object and $method is the name of the method that we want to call. I can dynamically call any method this way. Is there any C# equivalent to this? Or am I just "doing it wrong"? I have a plugin/module loaded in ...

Application plugin system

I’m writing an ASP.NET MVC 2 application where developers could extend it with plugins. I’ve started to consider how create a plugin system. (e.g. like Joomla’s) I have some doubts about how to do this. I have searched over the net and I found that there are two potential solutions. using interfaces or abstract classes to implement me...

C# cannot call overloaded non-generic method from generic method

I have some legacy code with a method foo which has 700+ overloads: [DllImport("3rdparty.dll")] protected static extern void foo(int len, ref structA obj); [DllImport("3rdparty.dll")] protected static extern void foo(int len, ref structB obj); [DllImport("3rdparty.dll")] protected static extern void foo(int len, ref structC obj); //and ...

In java, how to call the constructor of the instance creator of the current class ?

I have a class say 'A', an object 'a' of which creates an object 'b' of class'B'. Now 'b' runs a method which wants to create a new instance of b's parent(please dont confuse it with inheritance) - the class which created 'b', which is 'A' as in here. Is this anyhow possible in Java ? Or maybe some design suggestion may work. Thanks ! ...

Compare fields of two unrelated objects

Hi. I've got two objects of different classes that share some fields with the same name and type. These two objects are not related to each other. There's no possibility for me to create an interface or a parent class. Now I want to compare those shared fields and as far as I know this should be possible using reflection. These are th...

How do you dynamially invoke a property, but only if its argument is a certain type?

I am trying to use reflection to get all the (settable) properties in my POCO (which take a string argument, for now, but I plan to expand to other types), and set them to something arbitrary. (I need to make sure the .Equals method is implemented properly.) I have some code in my unit tests that looks something like this (where t is th...

Do Java or .Net applications heavily rely on reflection or not?

Suppose I have a Java or C# application in which I have classes like Book, Library, Author, ... and I want an easy way to map these items to database, or show them in a data grid. I could implement interfaces for all these classes specifically for the data grid and for the database interaction, but this may mean quite some work whenever...

How to retrieve the generic type used in a generic IEnumerable in .net?

We have a DAL that we're using with NHibernate.Search, so classes that need to be indexed are decorated with an attribute Indexed(Index:="ClassName"), and each property that needs to be be indexed has an attribute Field(Index:=Index.Tokenized, Store:=Store.No) . When one wants the index to drill down special objects, there's the attribut...

Reflective helper java libraries

Hi all, There are some Java libraries that do stuff you would otherwise have to put in every single class. For example, I had to put a clone() method in every single class until I discovered Cloner, and I had to put XML handling code until I discovered XStream. Are there any more similar helper libraries like these? ...

Is it good practice to use reflection in your business logic?

I need to work on an application that consists of two major parts: The business logic part with specific business classes (e.g. Book, Library, Author, ...) A generic part that can show Books, Libraries, ... in data grids, map them to a database, ...). The generic part uses reflection to get the data out of the business classes withou...

Java Reflection calling constructor with primitive types

I have a method in my test framework that creates an instance of a class, depending on the parameters passed in: public void test(Object... constructorArgs) throws Exception { Constructor<T> con; if (constructorArgs.length > 0) { Class<?>[] parameterTypes = new Class<?>[constructorArgs.length]; for (int i = 0; i ...

Release Late-Bound Object in C#

Is there a way to release an object that was accessed using late-binding (i.e. created by the Activator.CreateInstance() method)? I have an application that transforms files from one format to another. The assemblies that perform these translations live in a folder in my application directory. When the application first starts up, I c...

base.Invoke with delegates

I am invoking a delegate and I'm not very informed about how it works and I have compilation errors because of it (Compiler Error CS1660). This is the code I have for it: base.Invoke( delegate { bool flag = (((this.layerPickPlaceProcess != null) && (this.robotComponent != null)) && ((((StateEnum) this.layerPickPlaceProcess...

Reflection - Can't create a new object instance C#

I am trying to create a plug-in type archetecure for my project. I would like the ability to load an assembly, get a type that is derived from an abstract base class in my project, instantiate it and load that derived type into the main processing object. My problem right now is that when I instantiate the object from the reflected ass...

How can I determine the accessibility of a MemberInfo instance?

I know the BindingFlags are used to fetch public and non-public members from a Type. But is there a way to determine if a MemberInfo instance (or derived like PropertyInfo, MethodInfo) is public or not (after it was returned from one of the methods on Type)? Thanx, Marc ...

Is there a way to know whether a C# method of a object is called or not?

Hi experts, Is there a way to know whether a C# method of a object is called or not using reflection? ...