reflection

.NET 4.0: Parameter naming inconsistency between Expression and MethodInfo

Hello there, I have just found some misterious behaviour while working with System.Linq.Expressions.Expression and System.Reflection.MethodInfo. The code is as follows: static void Main(string[] args) { Expression<Func<double, double, double>> example = (x, y) => Math.Sin(x); //Prints out "x, y": Cons...

get assembly by class name

is there any way to get the assembly that contains a class with name TestClass. i just know the class name,so i cant create instance of that. and Type objectType = assembly.GetType("TestClass"); didnt work for me ...

How to get the List of ContentPlaceHolders of a MasterPage on code-behind?

I need to get the list of ContentPlaceHolders of a MasterPage, but the property protected internal IList ContentPlaceHolders { get; } is protected internal, so we can't access them. Is there any way we could pull them up from the MasterPage (including Reflection)? Thanks. ...

Reflection : How to invoke methods which takes a class object as input

I am using reflection to invoke a method from another dll.That method takes a class object as input. How can i call that method. I tried copying the same class to both dlls and i created an object of that class and passed it. It throws invliad conversion error in complie time itself. Then i tried to let the function take an object as arg...

Formatter that generates IL code for String.Format

I was looking for an object formatter and templater. http://haacked.com/archive/2009/01/14/named-formats-redux.aspx I looked into HenriFormatter and when check performance found that for the same object Type first invocation - causes 15x more time than for next - 15k ticks, second was around 1k. I become digg, and found that its using ...

Filtering out auto-generated methods (getter/setter/add/remove/.etc) returned by Type.GetMethods()

I use Type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) to retrieve an array of methods for a given type. The problem is the returned MethodInfo could include methods that are generated by the compiler which I don't want. For example: property bool Enabled { get; } will get bo...

How do I use .NET type strings in my programs?

For example in a .NET app.config you might get <configuration> <configSections> <section name="MyConfig" type="MyAssembly.MyType, MyAssembly, PublicKeyToken=null" /> </configSections> ... </configuration> The signature in the type part seems to be standardized in a variety of .NET places but I have no idea how to do thi...

Get string name of property using reflection

There is a whole wealth of reflection examples out there that allow you to get either: 1. All properties in a class 2. A single property, provided you know the string name Is there a way (using reflection, TypeDescriptor, or otherwise) to get the string name of a property in a class at runtime, provided all I have is an instance of t...

minimal reflection in C++

hi i want to create a factory and i would like to use reflection for that. i jast need to create a object with given string and invoke only few known methods how i can do that? ...

I am getting XMLSerialisation exception when i try to use Assembly.Load and the second dll uses serialization

I need to refer to another dll using reflection. Problem is that the second dll uses serialisation. That throws xmlserialisation exception when i try to load using Assembly. Load(). When i load using Assembly.LoadFrom() i am not able to delete the second dll after it has been used by the first dll. Is there a way i can do that? ...

Delete / Kill / Remove UserControl and its events handlers

Hello, I dynamically create UserControls using Reflection: UserControl myConmtrol = (UserControl)Activator.CreateInstance(t); The UserControl may handle a Closing event but I do not know the name of the handler. When the Window hosting the UserControl closes I remove the UserControl from its parent Window and it disappears from the Wi...

Looking for an object graph tree-view control for WPF

I'm trying to find code or a pre-packaged control that takes an object graph and displays the public properties and values of the properties (recursively) in a TreeView. Even a naive implementation is ok, I just need something to start with. The solution must be in WPF, not winforms or com, etc... ...

C# Reflection on Nested Properties of a Class

I wanted to know how can I get the Value of Property in C#, but this property is of another Type. public class Customer { public string Name {get; set;} public string Lastname {get; set;} public CustomerAddress Address {get; set;} } So I'm able to get the property values of Name and LastName but I quite don't get how to get t...

IQueryable OfType<T> where T is a runtime Type

I need to be able to get something similar to the following to work: Type type = ??? // something decided at runtime with .GetType or typeof; object[] entityList = context.Resources.OfType<type>().ToList(); Is this possible? I am able to use .NET 4 if anything new in that allows this. ...

Java: newInstance of class thas has no default constructor

I'm trying to build an automatic testing framework (based on jUnit, but that's no important) for my student's homework. They will have to create constructors of some classes, and add them methods. Then, with the testing functions I provide, they will check if they went allright. What I want to do is, by reflection, create a new instanc...

C# Parameter count mismatch error while passing object array in invoke method( Reflection)

HI ,I am trying to call funtion dynamically here and passing argument , dont know why it throws error there. Assembly objAssembly; objAssembly = Assembly.GetExecutingAssembly(); //get the class type information in which late bindig applied Type classType = objAssembly.GetType("Project." +strClassname); //create the instance of class ...

Why does casting a Type[] to a Class[] throw a ClassCastException?

Today i was writing some heavy reflection-using code, and i came across this behavior i can't explain: why does Type[] types = ((ParameterizedType)m.getGenericReturnType()).getActualTypeArguments(); Class[] c = (Class[])types; Throw a ClassCastException, when iterating over that same array and casting every single element, i.e. for(T...

Howto build Subsonic 3 qeury with dynamic table and column names using reflection

I would like to construct a dynamic Subsonic 3 query using code to get a collection of a type. The SQL would like this: select * from @tableName where @columnName1 = @columnValue1 The subsonic query would look like this: List<object> = new DB.Select.From<getTypeClass(tableName)>.Where(columnName1).IsEqualTo(columnValue1).ExecuteTypeL...

LINQ where clause running against mapped object

If I want to run something like this BLL.Person person = (BLL.Person)repository.Single(item => item.Id == Id); Down in my single method I'd do something like this: public Resource Single(Expression<Func<BLL.Resource, bool>> where) { Resource resource = AsQueryable().FirstOrDefault(where); return resource; } protected IQuer...

User Control - Generic List Bindable Property

Hey SO, I am trying to create a User Control that accepts a generic List of CustomObject as a bindable property. I've hit a wall and can't figure it out. Any help would be greatly appreciated! I'd like it to look a little somthing like this : TabularReport.ascx [Bindable (true)] public IList<T> Source { get; set; ...