reflection

Looking inside a lambda / expression tree

Given either of the variables below, how can I 'inspect' them to obtain the parameter value passed in? i.e. 12345. System.Func<DateTime> f1 = () => DateTime.Now.AddDays(12345); System.Linq.Expressions.Expression<System.Func<DateTime>> f2 = () => DateTime.Now.AddDays(12345); Edit: The two answers below by Mika...

Java reflection where a method parameter is an interface.

First off let me say I am maintaining someone else's poorly designed code so I am limited in how much I can change it. Now what is happening is that they have created a series of methods that are invoked by reflection. One of those methods takes a Map as one of its arguments. At runtime this Map is implemented with a Hashtable. Here'...

Use reflection to to see if Controller is within an Area

How do use reflection to determine whether a Controller of a given type is within a Area in an ASP.net MVC project? I am trying to write a new ControllerTypeResolver for an MvcSiteMap and need to work out if the type I am resolving exists within an Area in or not. ...

why Type.GetType() return null

I have a class named "Criteria", a Repository named CriteriaReposiroty. CriteriaReposiroty reads a xml file and returns a list of Criteria public static Func<XElement, Criteria> BuildObjectFromXElement(string typeName) { ParameterExpression element = Expression.Parameter(typeof(XElement), "element"); List<Me...

Getting Enum value via reflection

I have a simple Enum public enum TestEnum { TestOne = 3, TestTwo = 4 } var testing = TestEnum.TestOne; And I want to retrieve its value (3) via reflection. Any ideas on how to do this? Thanks Mat ...

Access to private inherited fields via reflection in Java

I founded a way to get inherited members via class.getDeclaredFields(); and acces to private members via class.getFields() But i'm looking for private inherited fields. How can i achieve this? ...

Getting ReflectionTypeLoadException on 2nd attempt at reflection in .net 4

In my project I have the following helper method, which goes through all the assembly and gets all types that are subclasses of the BaseCamaFrom type. public static List<Type> GetAllTestActionFormTypes() { List<Type> types = new List<Type>(); // add all the types that are subclasses of BaseCamaForm to the _camaF...

How to know if a PropertyInfo is a collection

Below is some code I use to get the initial state of all public properties in a class for IsDirty checking. What's the easiest way to see if a property is IEnumerable? Cheers, Berryl protected virtual Dictionary<string, object> _GetPropertyValues() { return _getPublicPropertiesWithSetters() .ToDictionary(pi =...

c# excel 2007 late binding.

Hello, I have a small program that uses reflection to work with excel. This line of code is working fine with excel 2003, but not with 2007. Any ideas? Type objClassType = Type.GetTypeFromProgID("Excel.Application"); TY ...

Find all classes with an attribute containing a specific property value

Is it possible to find a class that is tagged with a custom attribute based on a value given to that attribute? Basically, I have classes that look like this - [MyAttr("CODE")] public class MyClass() {} From there I'm getting all the classes (Types) - var c = Assembly.GetExecutingAssembly().GetTypes().Where (...

Simple Generics -- Is this possible Method<typeof(T)>()?

I am attempting to create a generic mapping function that takes the values of a dictionary and its sub classes and maps them to the fields in T using reflection. Within object T, there are sub objects that must be drilled into, and through recursion, it seems like a pretty simple concept. However I am stuck -- and I'm not sure if it's ...

Best way to dynamically create classes instead of using a switch block

Currently I have my VaryByCustom functionality implemented in classes that implement an interface IOutputCacheVaryByCustom public interface IOutputCacheVaryByCustom { string CacheKey { get; } HttpContext Context { get; } } A class implementing this interface has a few conventions the name of the class will be "OutputCacheVaryB...

Problem with a conversion of a complexType FROM object TO XML

For those that like to resolve problems, here's a big one :P Well, I am developing a system using web services, where I send and receive XML as parameter (not normal parameters as Int, String, bool, etc). After I receive a XML, I validate the XML with the XSD and also I convert that to an object.. after the process I also convert that ...

Dynamically casting one type of delegate to another

I'm using reflection to grab a field that happens to be a delegate. I need to replace this delegate with my own, but the type of the delegate is private (so I can't create it from my method and assign it) I have a delegate type with an exactly matching signature, so is there some way I can dynamically cast my delegate to this other type...

How to Compare two class objecy with Reflection?

i try to compare two class comp1,comp2 i used method below: ComparerCollection(array_X, array_Y); but there are errors below. Arraylist generated from Ilist. how can i do that? namespace GenericCollecitonComparer { class Program { static void Main(string[] args) { myClass comp1 = new myClass() { ID ...

How do I obtain a list of Collections which contain Objects which Implement an Interface in C# or VB.net

I am new to .Net Programming and would like to know if Reflection is suitable for traversing an Object to discover Collections within an instance of a class. I am working with the Microsoft.SqlServer.Management.Smo Namespace. The plan is to connect to a database, determine what collections exists, then for each of those collections, if...

Reflection: Distinguishing event-field from field of delegate type on runtime

The main question I have is: Is it possible in reflection to distinguish a field of some delegate type from a field which is used by an event as storagefield? That comes down to the question: does the FieldInfo class contain information about whether it belongs to an event, as storagefield ? I can't find any properties which might tell...

Using reflection in android for backwards compatability

I was reading over at the android dev website about using reflections. But I'm really not grasping how to use it. I need this java file to run on a 1.5(SDK3) device but just ignore the new code and work fine on a 2.0(SDK5) and up phone. I have this Activity (posted below) and it's a simple webview. However, I want to have geolocation ena...

How to get (sub)class name from a static method in Python?

If I define: class Bar(object): @staticmethod def bar(): # code pass class Foo(Bar): # code pass Is it possible for a function call Foo.bar() to determine the class name Foo? ...

richtextbox text range attributes -- protected, hidden, backcolor, etc -- can i set them without selecting a range?

i want to be able to protect, hide, and highlight different ranges of text within a richtextbox without actually selecting the text -- which is what you seem to have to do for the SelectionProtected and SelectionBackColor or w/e properties. how can i do this programatically? I looked around in reflection and found the SetCharFormat met...