reflection

How do I inspect a Class in Objective-C?

Update I fixed up the code to eliminate duplication of overridden methods and track originator of property or method by implementing Mark's suggestion. Haven't tackled property types yet (will probably start with property_getAttributes() when I do). Also stripped out vestigial underscores. Basically I need a way to remind myself what ...

Check type of primitive field

I'm trying to determine the type of a field on an object. I don't know the type of the object when it is passed to me but I need to find fields which are 'long's. It is easy enough for Longs but the primitive long seems more difficult. I can make sure that the objects passed to me only have Longs not the primitives but I'd rather not. S...

Get value from nested class using reflection

public class CustomProperty<T> { private T _value; public CustomProperty(T val) { _value = val; } public T Value { get { return this._value; } set { this._value = value; } } } public class CustomPropertyAccess { public CustomProperty<string> Name = new CustomProperty<string>("cfgf...

Any solution for Class.getMethod() reflection and autoboxing?

I want to use Class.getMethod(String name, Class... parameterTypes) to find the method I need to invoke with the given parameters, but apparently as described in Bug 6176992 Java doesn't include autoboxing there. So if my reflected class has a method with a (String, int) signature you still get a NoSuchMethodException with a {String.c...

Reflection. What can we achieve using it?

Hi! I'm reading and learning about reflection in C#. It would be fine to know how can it help me in my daily work, so I want people with more experience than me tell me samples or ideas about what kinds of things can we achieve using it, or how can we reduce de amount of code that we write. Thanks. ...

SecurityExceptions using the HTML Helpers in third-party libraries

Can someone explain this paragraph on page 258(Pro ASP.NET MVC 1.0 Chapter 6: Using the HTML Helpers)? If you're writing a third-party library(as opposed to a web application) that uses the HTML helpers, never call the overloads that accept anonymous objects. Always call the overloads that accept dictionaries. Otherwise...

Add event handler dynamically having the delegate name in a string

Hi! I need to assign an eventHandler to an object, in this way: _Element.AddHandler(UIElement.MouseLeftButtonUpEvent, new RoutedEventHandler(Vars.Digit), true); but, in fact, I only have a string that contains "Digit" or other method name in the Vars object instance. It is possible to achieve this using reflection or other kind of t...

How to get the type contained in a collection through reflection

In some part of my code I am passed a collection of objects of type T. I don't know which concrete colletion I will be passed, other than it impements IEnumerable. At run time, I need to find out which type T is (e.g. System.Double, System.String, etc...). Is there any way to find it out? UPDATE: I should maybe clarify a bit more the ...

get type of a generic parameter in java with reflection

Is it possible to get the type of a generic parameter? An example: public final class voodoo { public static chill(List<?> aListWithTypeSpiderMan) { // Here I'd like to get the Class-Object 'SpiderMan' Class typeOfTheList = ???; } public static void main(String... args) { chill(new List<SpiderMan>(...

Portably passing arguments to PHP's ReflectionMethod::invokeArgs by reference

Seemingly something of a misnomer, as pass by reference is deprecated in PHP 5.3... anyway, what I'm trying to do is write a unit test framework using reflection, that allows you to pass arguments to a method which requires a reference. e.g. class Bar { function TestMethod($arg1, &$result) { $result = 'hello'; return...

GetGenericTypeDefinition returning false when looking for IEnumerable<T> in List<T>

Following this question, why does enumerable in this: Type type = typeof(List<string>); bool enumerable = (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)); return false? Edit 1 As the above doesn't work, what would be the best way to determine if a class implements IEnumerable? ...

Custom configuration issue (c#)

Hi everybody, I'm woking on a project that requires to extend ConfigurationSection for every configuration object. Configuration information is stored into the database and it can be overriden by custom local configuration. It's the opposite order as I mentioned (local values are merged to database info, proritizing database). Classed ...

Getting object instance by string name in scala

I need the object (or "singleton object" or "companion object"... anything but the class) defined by a string name. In other words, if I have: package myPackage object myObject ...then is there anything like this: GetSingletonObjectByName("myPackage.myObject") match { case instance: myPackage.myObject => "instance is what I wanted"...

Smart way to find the corresponding nullable type?

How could I avoid this dictionary (or create it dynamically)? Dictionary<Type,Type> CorrespondingNullableType = new Dictionary<Type, Type> { {typeof(bool), typeof(bool?)}, {typeof(byte), typeof(byte?)}, {typeof(sbyte), typeof(sbyte?)}, {typeof(char), typeof(char?)}, {typeof(decimal), typeof(decimal?)}, {typeof(...

How do I get a list of all loaded Types in C#?

I need to retrieve all enums that were loaded from a given set of Assemblies. ...

is this possible in C# GetStringName(o.Property) or o.Property.GetPropertyStringName() ?

I need some method that is going to get the property's string name, I don't know if this is possible in C#, is it ? ...

Creating an instance of HttpPostedFile with Reflection

Is there a way to create an instance of HttpPostedFile with Reflection. I tried: var obj = (HttpPostedFile)typeof(HttpPostedFile).GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null).Invoke(null); var obj2 = Activator.CreateInstance(typeof(HttpPostedFile) ...

How do I iterate a generic reflected method?

In my CMS I have a load of modules which allow me to do some clever item listing stuff. I am trying to use them to pull out a list of their child objects via reflection, but am getting stuck with the level of generics involved. I have got as far as this method: var myList = moduleObj.GetType().GetMethod("ChildItems").Invoke(moduleObj, ...

Constructor on type 'System.Web.HttpPostedFile' not found.

I'm trying to create an instance of HttpPostedFile with var obj2 = Activator.CreateInstance( typeof(HttpPostedFile), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { }, System.Globalization.CultureInfo.CurrentCulture ); but I'm getting the error 'Constructor on type 'System.Web.HttpPostedFile' ...

Microsoft's Unity and PowerShell

In a C# solution, I have multiple class libraries for the domain model, services, and repositories. I configured Unity in web.config of the main website project so that it knows what concrete objects to map to the services and repositories. For quick testing, though, I'd like to use PowerShell to load the assemblies and manipulate classe...