reflection

SelectedIndexChange event not firing when using through reflection

I have a windows form with a listview control. I have a selectedIndex changed event where i am performing some action. Through reflection I am trying to set the value of the list view. But the event is not getting fired. Any help will be helpfull. Edit The event looks like private void LV1_SelectedIndexChanged(object sender, Event...

How do I enumerate all items that implement a generic interface?

I have two interfaces, a generic and a non-generic that have an inheritence hierarchy: public interface IGenericRelation<TParent, TChild> : IRelation public interface IRelation The generic one is implemented by several server controls that are loaded dynamically and I wish to enumerate on the collection of controls that implement th...

How to know if the code is inside TransactionScope?

What is the best way to know if the code block is inside TransactionScope? Is Transaction.Current a realiable way to do it or there are any subtleties? Is it possible to access internal ContextData.CurrentData.CurrentScope (in System.Transactions) with reflection? If yes, how? Thank you in advance. ...

Reflectively Executing Code in .Net

How do you reflectively, or dynamically, execute code in .Net? If an XML contains something inside '[]' I want to handle the text not as text but as code: <Name>DateZero</Name> <Value>DateTime.Now.AddDays(-2)</Value> <Name>DateOne</Name> <Value>[DateTime.Now.AddDays(-1).ToString("MM/dd/yy")]</Value> <Name>DateTwo</Name> <Value>[DateT...

Set similar object properties in another object.

I have two objects that contain some properties that are exactly the same (same name, type). What I want to do is populate one object's identical properties with another object's properties. I am trying to do this in code, but it's not working. The Bin object's properties are not being set. class Basket{ public Basket(int itemId, in...

How to determine if the MethodInfo is an override of the base method

I'm trying to determine if the MethodInfo object that I get from a GetMethod call on a type instance is implemented by the type or by it's base. For example: Foo foo = new Foo(); MethodInfo methodInfo = foo.GetType().GetMethod("ToString",BindingFlags|Instance); the ToString method may be implemented in the Foo class or not. I want t...

Testing if object is of generic type in C#

I would like to perform a test if an object is of a generic type. I've tried the following without success: public bool Test() { List<int> list = new List<int>(); return list.GetType() == typeof(List<>); } What am I doing wrong and how do I perform this test? ...

Reflect over a x86 assembly from a "Any CPU" built application on x64 bit OS

Hey everyone, I have a .Net app that's compiled as "Any CPU". I am running it on a x64 OS so it's running as 64bit. The application loads other assemblies that the user provides. It uses reflection of course to read types from the user provided assembly. Everything works fine if the user assembly is compiled as "Any CPU". But if the ass...

Removing Routed Event Handlers through Reflection?

Hi! Background: I'm using WPF and C# (3.5) and am working on an app that allows a user to view a form/window/usercontrol that's already part of a compiled assembly. When they view it, they should be able to click on any control (buttons, textboxes, even labels), a little popup editor should appear by the control where they can then ty...

Differentiating between generic and non-generic version of overloaded method using reflection

I'm having some trouble using reflection to differentiate between a non-generic and a generic method on a generic class. Here's a test case I'm working with: public class Foo<T> { public string Bar( T value ) { return "Called Bar(T)"; } public string Bar( int value ) { return "Called Bar(int)"; } public static void CallBar<TR>(F...

c# Reflection object[] issue

Hello, I am trying to use reflection to create object array of the type created from reflection like the folowing: Client[] newArray = new Client[] {client1, client2}; I need to somehow get the Client object type to create the object so it can be passed through. Any help would be greatly appreciated. Cheers, Rob object clientObjec...

PropertyInfo Sub Properties

I have a linq Context that I am looking at all the data Tables, I am trying to get the list of fields in all tables foreach (var code in ctx.GetType().GetProperties()) { Console.WriteLine(code.PropertyType + " - " + code.Name + " "); if (code.PropertyType.ToString().Contains("System.Data.Linq.Tab...

Get MethodInfo for Extension Method

I cant get the method info for an extension method as I would suspect. Whats wrong? _toStringMethod = typeof(ObjectExtensions).GetMethod("TryToString", BindingFlags.Public | BindingFlags.Static); ...

C# How can I get the value of a string property via Reflection?

public class Foo { public string Bar {get; set;} } How do I get the value of Bar, a string property, via reflection? The following code will throw an exception if the PropertyInfo type is a System.String Foo f = new Foo(); f.Bar = "Jon Skeet is god."; foreach(var property in f.GetType().GetProperties()) { object o...

How do you filter a collection of objects in a base class based on the type of the sub class created?

I wrote this example to help explain. As you can see I have an object hierarchy. I'd like to modify the GetFeatures() function to only return the features added by constructor of object type I instantiated. For example, BasicModel.GetFeatures(new LuxuryModel()) should only return the features "Leather Seats" and "Sunroof". I don't mind u...

C# Reflection: Accessing the fields of a struct

Why does the following code produce no output? static void Main(string[] args) { FieldInfo[] fi = typeof(MyStruct).GetFields(BindingFlags.Public); foreach (FieldInfo info in fi) { Console.WriteLine(info.Name); } } public struct MyStruct { public int one; public...

Java Reflection isArray() always false

Hey anyone, I got a question about Java Reflections: I have to checkout, if a certain field of a class is an array. But my problem is: If i run isArray() on the attribute of the class directly, it works. But if I use it in the way below, it won"t work. I guess because the "real" array is in this Field class? Any idea how i get it to work...

How to getDefinitionByName of a packageless class in AS3?

Say you have a flexunit test that looks like this: package foo { import flexunit.framework.TestCase; import flash.utils.getDefinitionByName; import flash.utils.getQualifiedSuperclassName; class DescribeTypeTest { public function testDescribeInnerType():void { var currentInstance:ChildBar = new ChildBar(); ...

What is the VB equivalent of Java's instanceof and isInstance()?

In the spirit of the c# question.. What is the equivalent statements to compare class types in VB.NET? ...

C# using reflection to create a struct

I am currently writing some code to save general objects to XML using reflection in c#. The problem is when reading the XML back in some of the objects are structs and I can't work out how to initialise the struct. For a class I can use ConstructorInfo constructor = SomeClass.GetConstructor(Type.EmptyTypes); however, for a struct, t...