reflection

How do I use reflection to get the nested property

I am writing a TwoWay Binding control for ASP.NET. I finally got things working. I'm rebinding using the following code: private void RebindData() { // return if the DataValue wasn't loaded from ViewState if (DataValue == null) return; // extract the values from the two-way binding template IOrderedDictionary v...

How can I write a generic container class that implements a given interface in C#?

Context: .NET 3.5, VS2008. I'm not sure about the title of this question, so feel free to comment about the title, too :-) Here's the scenario: I have several classes, say Foo and Bar, all of them implement the following interface: public interface IStartable { void Start(); void Stop(); } And now I'd like to have a contai...

log4net when to log?

Hi there, DOes anyone have any good information with regards to when to log, I was thinking of logging an INFO type when i enter each c# method and recording another info when exiting.. Is this considered good or bad? Will i see a performance hit? If i do record an INFO when i enter a method, the idea would be to record the method nam...

How can I find out all the references for the current project and tell which ones derive from a particular base class in C#?

Due to politics at the very large finanial institution for which I work, I am not able to use Castle Project's ActiveRecord implementation, but like the pattern so much I have implemented it myself. This is complete, and now management is looking for a GUI tool to browse all the activerecord classes, search for instances and manage data....

Accessing Java static final ivar value through reflection

Can the value of a Java static final class variable be retrieved through reflection? ...

C# Reflection: Get *all* active assemblies in a solution?

Heres my problem: I have 2 projects - one 'common' projects with acts like a library with all kinds of support code, and the actual program that uses said project in many of its calls. We'll call these projects "Common" and "Program". They are both in the same solution. Within "Common", I have a class for commo reflection tasks, like...

Reflection in C++

Hi, everyone. This is my very first question in SO. I've been working for years with Java. During those years, I've made extensive (or maybe just frequent) use of Reflection, and found it useful and enjoyable. But 8 months ago I changed my job, and now Java is just a memory, and I'm getting my hands on C++. So now I'm wondering if there...

Getting values of a generic IDictionary using reflection

I have an instance that implements IDictionary<T, K>, I don't know T and K at compiletime, and want to get all elements from it. I don't want to use IEnumerable for some reason, which would be the only non-generic interface implemented by IDictionary. Code I have so far: // getting types Type iDictType = instance.GetType().GetInterface...

Reflection performance for Data Access Layer

Hi all, I had created a framework for a project in the past that one of it’s functionalities was to load the Database info into my business entity classes (only properties no methods) and from the Business entity classes to the database loading the parameters collection of the stored procedure to be executed. To this on that project I d...

In C#, how do I add event handlers to an object based on names?

I'm am trying to add event handlers to 'myObject' based on the name of an event or events. 'myObject' has an event called 'MyEvent' and I have a public event handler called 'MyEventHandler' (which I don't need to get by name but do it below to get a MethodInfo). This is what I have so far: EventInfo eventInfo = myObject.GetType().GetEv...

Referring to the property itself in C#. Reflection? Generic? Type?

Please bear with me if this question isn't well formulated. Not knowing is part of the problem. An example of what I'd like to accomplish can be found in PropertyChangedEventArgs in WPF. If you want to flag that a property has changed in WPF, you do it like this: PropertyChanged(this, new PropertyChangedEventArgs("propertyName")); Yo...

C# Reflection: getting a nested objects properties

I am having trouble getting a nested objects properties. For the example I am working with, I have 2 Classes: public class user { public int _user_id {get; set;} public string name {get; set;} public category {get; set;} } public class category { public int category_id {get; set;} public string name {get; set;} } Simple ...

Finding the object field corresponding to a reference parameter in C#

When you write an iterator function in C#, using yield syntax, the compiler internally translates your function into a class. So, if I write something like this: IEnumerator<int> MyIterator () { for (int i = 0; i < 10; i++) yield return i; } Invoking MyIterator() constructs a class with a private field for i, instead of using a ...

Setting properties of an object through reflection with different properties types

Hi, I am using reflection to populate the properties of an object. These properties have different types: String, Nullable(double) and Nullable(long) (don't know how to escape the angle brackets here ...). The values for these properties are coming from a dictionary of (string, object) pairs. So, for example my class has the followin...

What exactly is Reflection and when is it a good approach?

What exactly is Reflection? I read the Wikipedia article on this subject and I understand that it is a kind of meta-programming, where the program can modify itself at run-time, but what does this mean? In what kind of situations is this a good approach and when is it the best to use it? ...

How can I get the name of a python class?

When I have an object foo, I can get it's class object via str(foo.__class__) What I would need however is only the name of the class ("Foo" for example), the above would give me something along the lines of "<class 'my.package.Foo'>" I know I can get it quite easily with a regexp, but I would like to know if there's a more "clean...

C# INotifyPropertyChanged on properties of a dynamically created object?

(update) ICustomTypeDescriptor works for my Windows Forms app, but not for Silverlight; Not supported. I will keep investigating this idea though and see where i get to. (/update) I have, say a few switch panels (for those that like analogies). Each of these switch panels has switches that have a Name(string) can be in state(bool) of On...

What is the best way to compare several javabean properties?

I need to compare dozens of fields in two objects (instances of the same class), and do some logging and updating in case there are differences. Meta code could look something like this: if (a.getfield1 != b.getfield1) log(a.getfield1 is different than b.getfield1) b.field1 = a.field1 if (a.getfield2!= b.getfield2) log(a.getfield...

Deserialization error in MEF due to missing assemblies

I'm using MEF. I serialize one of the objects which relies on one of the loaded assemblies. Now when I try to deserialize this object it throws "Unable to find assembly" exception. MEF loads the assemblies before this deserialization in another class (I assume that the scope of this is application wide, it loads them into a public prop...

Generic constructors and reflection

Is it possible to see which constructor was the generic one? internal class Foo<T> { public Foo( T value ) {} public Foo( string value ) {} } var constructors = typeof( Foo<string> ).GetConstructors(); The property 'ContainsGenericParameters' returns me for both constructors false. Is there any way to find out that constructors[0...