reflection

.Net - Reflection set object property

Is there a way in .Net c# 3.5 I can use reflection to set a object property ? Ex : MyObject obj = new MyObject(); obj.Name = "MyName"; I want to set obj.Name with reflection. Something like : Reflection.SetProperty(obj, "Name") = "MyName"; Is there a way of doing this ? ...

Python Reflection and Type Conversion

In Python, functions like str(), int(), float(), etc. are generally used to perform type conversions. However, these require you to know at development time what type you want to convert to. A subproblem of some Python code I'm trying to write is as follows: Given two variables, foo and bar, find the type of foo. (It is not known at ...

Getting Argument Names In Ruby Reflection

I would like to do some fairly heavy-duty reflection in the Ruby programming language. I would like to create a function which would return the names of the arguments of various calling functions higher up the call stack (just one higher would be enough but why stop there?). I could use Kernel.caller go to the file and parse the argument...

How do reflection and remoting work internally?

I am curious to know how Reflection and Remoting in .net work internally. I also hear that .net can use remoting to communicate with applications written in other languages (such as Java). How does that work? This is probably a large question so an answer that briefly touches upon each question is reasonable. ...

Invoke generics overloaded method using reflection

Hi, I need to invoke an overloaded method using reflection. My classes as below: public static Transformer { //Overloaded method with generics parameter. First Transform Method public static TranformerResult Transform<T>(object [] entities, List<T> dataContract) where T:class { return transformerResult; ...

Is Java Reflection on Inherited Methods Different in Windows and Linux?

While setting up Hudson for continous integration testing (on a JeOS server), I've come across some strange behaviour I'm hoping the fine people at SO can explain to me. Our unit tests depend heavily on the use of domain objects, with lots of properties that must be set (due to null constraints in the database). In order to keep our tes...

How does "static reflection" work in java? (ex. in mockito or easymock)

I'm a .NET guy - and I mainly code in C#. Since C# 3.0, we can leverage lambda expressions and expression trees to use static reflection. For example, it is possible to implement GetMethodName in the following snippet to return the name of the method passed in parameter: string methodName = GetMethodName( o => o.DoSomething()); Console...

Data Auditing in NHibernate using events

I'm revisiting and re-implementing the code that caused me to ask this question about data auditing in NHibernate. However this time, I want go with Sean Carpenter's suggestion and implement the ISaveOrUpdateEventListener (new in NHibernate 2.x) I want to add a row in a database for each change to each property with the old value and t...

Determining if a parameter uses "params" using reflection in C#?

Consider this method signature: public static void WriteLine(string input, params object[] myObjects) { // Do stuff. } How can I determine that the WriteLine method's "myObjects" pararameter uses the params keyword and can take variable arguments? ...

Dynamic use of typeof

I'm using reflection to get the properties of an object and there's no difficulty in that but I need to make my class even more generic so basically what I'm trying to do is the following: PropertyInfo[] properties = (typeof ("ObjectName")).GetProperties(BindingFlags.Public | BindingFlags.Instance); Or something similar. Notice the us...

C# - Get Private Field from Static Class

Is there any way to use reflection to get the value of a private member on a static class? ...

c# : Type.GetType called from a dll on exe type string

I've the following class in XmlSer.dll namespace xmlser { public class XmlSer { public Type test(string s) { return Type.GetType(s); } //...other code } } and the following code in MyApp.exe, which links XmlSer.dll as a reference nam...

JavaScript triggering - reflection of vb.net api calls?

Can you call a vb.net api function using reflection from javascript code? I just started playing around with reflection, I have this snippet of code that works, I want to change it to a javascript page. Dim RawPlugin As Reflection.Assembly RawPlugin = Reflection.Assembly.LoadFrom("C:\Inetpub\wwwroot\demo\MasterApplication\getSession\bi...

Custom Attributes on Class Members

I am using a Custom Attribute to define how a class's members are mapped to properties for posting as a form post (Payment Gateway). I have the custom attribute working just fine, and am able to get the attribute by "name", but would like to get the attribute by the member itself. For example: getFieldName("name"); vs getFieldName(...

In Java, given an object, is it possible to override one of the methods?

I have an object of class A. I want to override one of the methods of that class. Can this be done? More specifically, I have an object that is being injected into a field. I need to override one of the methods, before I can use it. I am trying to see if Reflection could help solve the problem. Note that the method that I am trying o...

Get current MethodBase through reflection

Can I get the current method's MethodInfo somehow? ...

Concatenating each non-empty parameter and its value

I have a method that accepts a bunch of strings in seperate parameters public string GetQueryString(string string1, string string2, string string3...) It should return a string in the form of "string1:value1 string2:value2 string3:value3..." Because I don't want to put reflection logic in the callers of GetQueryString, I think work...

Is reflection reverse engineering?

You can find out a great deal about the internals of an application through reflection, it's exposed by the .NET BCL (base class library) and it makes it trivial to retrieve actual IL for any .NET method. Reverse engineering on Wikipedia: Reverse engineering is the process of discovering the technological principles of a device,...

How do I find out whether an object's type is a subclass of IEnumerable<T> for any value type T?

I need to validate an object to see whether it is null, a value type, or IEnumerable<T> where T is a value type. So far I have: if ((obj == null) || (obj .GetType().IsValueType)) { valid = true; } else if (obj.GetType().IsSubclassOf(typeof(IEnumerable<>))) { // TODO: check whether the generic parameter is a value type. } ...

Workaround for MethodBase.GetCurrentMethod() on Compact Framework 3.5

I want use a Linq IQueryable Toolkit in project on .NET Compact Framework. The Linq capabilities in CF is little bit shapred - i.e.: IQueryable interface is not available. So I've found third party libraries, which implements missing functionality what I need. Now I have problem with missing method "MethodBase.GetCurrentMethod()". There...