reflection

How find source code for eval'd function in PHP?

I am trying to find a way to get the source code for (user defined) PHP functions in a string. For normal code this is easy, using reflection I can find the file and linenumbers where the function is defined, then I can open the file and read the function source code. This will not work if a function is defined in eval'd code. I do not...

How do I find the type of the object instance of the caller of the current function?

Currently I have the function CreateLog() for creating a a log4net Log with name after the constructing instance's class. Typically used as in: class MessageReceiver { protected ILog Log = Util.CreateLog(); ... } If we remove lots of error handling the implementation boils down to: [EDIT: Please read the longer version of C...

C# VS 2005: How to get a class's public memeber list during the runtime?

Hi, I'm trying to get a class memeber variable list at run time. I know this probably using typeof and reflections. but can't find an example. Please someone shed light for me. Here is pseudo code example: Class Test01 { public string str01; public string str02; public int myint01; } I want something like this (pseudo code): Te...

How to access the Index Of A Generic.List By Reflection??

ok, ive a class and i pass an object as property. the object that i pass is a List<X> in my class im trying to access the Object index by reflection BUT I CAN'T!!! Example: this class works i just wrote down the part i want to show you and i need help. class MyClass { private object _recordSet; public object RecordSet {...

Taking out all classes of a specific namespace

Hi there is there a possibility to get an object from a specific namespace? Perhaps with the System.Reflections? I want to get all objects from type ITestType in the namespace Test.TestTypes as Objects so that I have a list of instances of TestType1, TestType2, TestType3 and so on. Can Someone help me? I don't know where to search for th...

How do I compile an Expression Tree into a callable method, C# ?

Hi, I have an expression tree I have created by parsing an Xml using the expression class in C#. See this question. I only have Add, Subtract, Divide, Multiply, Parameters, And and Or in my Expression Tree. Is there a way to convert this ExpressionTree into a callable method? ...or do I have to emit the IL manually? Kind regards, ...

How to determine type of dynamically loaded usercontrol?

I have an application the will load usercontrols dynamically depending on the user. You will see in the example below that I am casting each user control via switch/case statements. Is there a better way to do this? Reflection? (I must be able to add an event handler Bind in each control.) override protected void OnInit(EventArgs e) {...

Why is reflection called reflection instead of introspection?

What is the origin of the term reflection? It seems more like introspection. Why isn't it called that? Introspection: A looking inward; specifically, the act or process of self-examination. Reflection: the act of reflecting or the state of being reflected. an image; representation; counterpart a fixing of the thoughts on something;...

Easiest way to get a common base class from a collection of types.

I'm building a custom property grid that displays the properties of items in a collection. What I want to do is show only the properties in the grid that are common amongst each item. I am assuming the best way to do this would be to find the the common base class of each type in the collection and display it's properties. Is there any e...

Dependency Injection while dynamic assembly loading

i have a winforms applicatoin that has a lot of implementations of IOrderDataLoader. Other teams are starting to build their own new implementations of IOrderDataLoader. So we switched our app to look in a directories of Dlls and load all classes that implement IOrderDataLoader using reflection. This way other groups can deploy their ...

can I reflectively instantiate a generic type in java?

Is it possible to reflectively instantiate a generic type in Java? Using the technique described here I get an error because class tokens cannot be generic. Take the example below. I want to instantiate some subclass of Creator that implements Creator. The actual class name is passed in as a command line argument. The idea is to be able ...

GetProperties() to return all properties for an interface inheritance hierarchy

Assuming the following hypothetical inheritance hierarchy: public interface IA { int ID { get; set; } } public interface IB : IA { string Name { get; set; } } Using reflection and making the following call: typeof(IB).GetProperties(BindingFlags.Public | BindingFlags.Instance) will only yield the properties of interface IB, wh...

Why does C++ not have reflection?

This is a somewhat bizarre question. My objectives are to understand the language design decision and to identify the possibilities of reflection in C++. Why C++ language committee did not go towards implementing reflection in the language? Is reflection too difficult in a language that does not run on a virtual machine (like java)? If...

Why does GetProperty fail to find it?

I'm trying to use reflection to get a property from a class. Here is some sample code of what I'm seeing: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Reflection.PropertyInfo[] tmp2 = typeof(TestClass).GetProperties(); System....

How would I get the column names from a Model LINQ?

I am looking to get a list of the column names returned from a Model. Anyone know how this would be done, any help would be greatly appreciated. Example Code: var project = db.Projects.Single(p => p.ProjectID.Equals(Id)); This code would return the Projects object, how would I get a list of all the column names in this Model. Thanks...

Is there a general "backend" library for Java reflection

I'm currently working with a specialized, interpreted, programming language implemented in Java. As a very small part of the language, I'd like to add the ability to make calls into Java. Before I dive into all of the nitty-gritty of reflection, I was wondering if anyone knew of a general library for doing the "backend" part of invoking...

Find Items that are Not [Serializable]

I was wondering if anyone knows of a quick way or if anyone has written a reflection tool to tell which objects in a solution are not marked as serializable. I'm switching a site over to a StateServer and i need to have all objects marked as serializable. I don't want to miss any. Also, second part do enums have to be serializable? T...

Best way to get sub properties using GetProperty

public class Address { public string ZipCode {get; set;} } public class Customer { public Address Address {get; set;} } how can I access eitther "ZipCode" or "Address.ZipCode" with reflection? For example: Typeof(Customer).GetProperty("ZipCode")? ...

Read-only PropertyGrid

Hi, I need to show an object in PropertyGrid with the following requirements: the object and its sub object must be read-only, able to activate PropertyGrid's CollectionEditors. I found a sample that's closely match to what I need but there's an unexpected behaviour I couldn't figure out. I have more than one PropertyGrids each for dif...

How to get all properties of an object and its sub objects

Hi, I have a similar question to this one except I need to loop all the sub objects and change the property to read-only Please check my code below. This one loop only the main object. When I tried to loop its sub objects, I got an overflow. Thanks. Public Class ReadOnlyTypeDescriptor Inherits CustomTypeDescriptor Priva...