reflection

AppDomain.CreateInstance is not following the rules

According to How the Runtime Locates Assemblies step 2 is Checking for Previously Referenced Assemblies. However, in the code below you can see that this is definitely not happening. In the first line, an assembly is loaded (which should make it a "previously referenced assembly" for all future calls.) However, a couple lines later wh...

How could Reflection not lead to code smells?

I come from low level languages - C++ is the highest level I program in. Recently I came across Reflection, and I just cannot fathom how it could be used without code smells. The idea of inspecting a class/method/function during runtime, in my opinion, points to a flaw in design - I think most problems Reflection (tries to) solve could...

How do I Immediately Validate a Newly Inserted Row in a Silverlight 3 Datagrid?

I have a Silverlight 3 tools library with a custom DataGrid user control. This grid has no direct access to the WCF RIA Services entity types so I'm using reflection to add a new item when the user clicks on the grid when it's empty: private void InsertEmptyRecord() { if (this._dataGrid.ItemsSource == null) return; Type...

Creating a generic IList instance using reflection

I am trying to create a generic list of objects using reflection. The below code throws an error Cannot create an instance of an interface. . I could change the IList to List and it works fine, but I was wondering if there is way to get this working with an IList. var name = typeof (IList<T>).AssemblyQualifiedName; Type type = ...

Iterating over arrays by reflection

Hi Everyone I am doing some reflection work and go to a little problem. I am trying to print objects to some GUI tree and have problem detecting arrays in a generic way. I suggested that : object instanceof Iterable Would make the job ,but it does not, (obviously applies only to Lists and Set and whoever implements it.) So how ...

Reflection: How to Invoke Method with parameters

Hello, I am trying to invoke a method via reflection with parameters and I get "object does not match target type". If I invoke a method without parameters it works fine. Based on the following code if I call the method Test("TestNoParameters") it works fine. However if I call Test("Run") I got an exception. Is something wrong with my c...

How might I count the number of int members defined for a Java class?

I have a class that stores a large number of int member variables, each defined as follows: public final static int int1 = int1value; public final static int int2 = int2value; ... public final static int int106 = int106value; There is a second class that needs to do a loop based on the number of ints in the first class. How would I go...

Register all declared child classes of a class in C#

In a proof-of-concept project I'm working on, I have a generic abstract class that I expect to be extended by a number of child classes: public abstract class Pet { public abstract string PetTypeName {get;} } public class Dog : Pet { public override string PetTypeName { get { return "Dog"; } } } I'd like to have a static coll...

Using Reflection to set a static variable value before object's initialization? (C#)

Is there anyway to set a value of a static (private) variable without needing to initalize the object? The SetValue method requires an instance, but I'm hoping there's a way to get around this. Thanks! ...

Reflection API for Scala

Does anyone know the status of a fully-featured reflection API for Scala? I know that you can use Java's reflection API to do simple things but this does not work well with Scala's language features. I found an interesting article describing an experimental Scala Mirroring API but as far as I know this is still experimental. I've als...

Assembly name from namespace string

Is there a way of getting the assembly name from a namespace string? Eg, get "mscorlib" from "System". The reason for my question is I'm creating Boo scripts method-by-method and am required to add namespaces programmatically. The resulting string in Boo would read: import System from mscorlib I could obviously pass in a collection...

Is there a way to iterate and reflect the member names and values contained in enumerations?

Let's say I have the following enum: public enum Colors { White = 10, Black = 20, Red = 30, Blue = 40 } I'm wondering if there is a way to iterate through all the members of Colors to find the member names and their values. ...

How to find out if a property is an auto-implemented property with reflection?

So in my case i am doing discovery of the structure of a class using reflection. I need to be able to find out if a property is an auto-implemented property by the PropertyInfo object. I assume that the reflection API does not expose such functionality because auto-properties are C# dependent, but is there any workaround to get this info...

How to collect all classes implementing an interface at runtime?

For running all my test classes automatically, I look for all class files inside a dedicated directory, convert the path to a package name and check if this class implements the given interface: try { Class<? > myTestClass = Class.forName( constructedClassName ); if( myTestClass.isInstance( MyTestInterface.class ) ) { te...

XNA Collision Detection - Vector2.Reflect - Help Calculating the Normal of a Circle Sprite - C#

I'm having trouble wrapping my mind around how to calculate the normal for a moving circle in a 2d space. I've gotten as far as that I'm suppose to calculate the Normal of the Velocity(Directional Speed) of the object, but that's where my college algebra mind over-heats, any I'm working with to 2d Circles that I have the centerpoint, ra...

C# Dynamic Instantiation

I am in need of some help here about doing a dynamic instantiation in C#. What I want to accomplish is to be able to use a string variable that is used as the name in the instantiation. I think you can use reflection or something, but I am lost on this one. Here is my test code snippet and hopefully someone has an answer. Averages is ti...

Using reflection in Java to create a new instance with the reference variable type set to the new instance class name?

All the examples I look at for reflection show creating a new instance of an unknown implementation, and casting that implementation to it's interface. The issue with this is that now you can't call any new methods (only overrides) on the implementing class, as your object reference variable has the interface type. Here is what I have: ...

Why should I care about RTTI in Delphi?

I've heard a lot about the new/improved RTTI capabilities of Delphi 2010, but I must admit my ignorance...I don't understand it. I know every version of Delphi has supported RTTI...and I know that RTTI (Runtime Type Information) allows me to access type information while my application is running. But what exactly does that mean? Is Del...

Is there a quicker/better way to get Methods that have attribute applied in C#

I have a marker interface something like this: [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class MyAttribute : Attribute { } And i want to apply it to methods on different classes in different assemblies... Then I want to Get a MethodInfo for all methods that have this attribute applied. I ne...

NewLateBinding.LateSet to reflection call.

Assume I have an Excel.PivotField, and I need to setHiddenItemsList on my object. With VB.NET and Option Strict Off & Option Explicit Off this would result in: Dim field as Excel.PivotField = MyFunctionCall() field.HiddenItemsList = GetHiddenItems() While this works with this security setting, it obviously doesn't work when you set O...