I would like to get type from generic type fullname like that : var myType = Type.GetType("MyProject.MyGenericType`1[[MyProject.MySimpleType, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"); But it seems to not work with gen
I use the nhibernate interceptor to compare values of the old state and the current state of the entity properties but some of the properties are of type ICollection so could anyone guide me about how to check if an object is of type ICollection this
UPDATE: 6 months later, and I just came across this answer: Is it legal to index into a struct?: Answer by Slava . I think this is a MUCH better solution than any of the ones provided here, as there is absolutely no undefined behavior. Hopefully this
I have an object like os.Stdout and I want to know if it supports io.WriteCloser on my platform. I can get the type of my object, but it doesn't tell me anything about interfaces. package main import ("fmt"; "reflect"; "os")
I am receiving JSON messages from an API (I have full control of the messages sent). The messages look like this : { "function": "function_name", "arguments": { "arg1": "Value", "arg2": "Val
The following code (-> (.getField (Class/forName "ccg.flow.processnodes.text.retrievers.Dictionary.Dictionary") "wordsTuples") .getType) tells me that wordsTuples is a java.util.ArrayList. But what I would like to be able to learn i
Is there a way to compare discriminated unions by their case-identifiers in F#? type MyUnion = | MyString of string | MyInt of int let x = MyString("hello") let y = MyString("bye") let z = MyInt(25) let compareCases a b = // compareCas
I'm a little confused about the difference between the getFields method and the getDeclaredFields method when using Java reflection. I read that getDeclaredFields gives you access to all the fields of the class and that getFields only returns public
For reasons out of the scope of the question, I'm needing to dynamically create an instance of a child class that inherits from a base class, calling a constructor that doesn't exist with an argument passed to the base class constructor Using example
I have some classes with common properties, however, I cannot make them derive from a base type (LINQ-to-SQL limitations). I would like to treat them as if they had a base type, but not by using Reflection (performance is critical). For example: publ
I need to get the type of the item of a collection. For retrieving the class of a single instance I use the following code: classUnderTest.getName() But, how can I retrieve the class of the items of the following collection? Collection collection = (
I apologize if this has been asked and answered before but I was not able to find an answer. I know how to walk through the controls collection and get a listing of all the controls including child controls. void printControlTree(Control ctl, int ind
Is it possible in C# to create a type at runtime that inherits from a generic class where the template parameter for the base class is the current class being constructed? This will compile fine: // I have this class: public class OtherClass<T> wher
I don't do much of reflection so this question might be obvious. For e.g. I have a class: public class Document { private String someStr; private byte[] contents; //Getters and setters } I am trying to check if the field contents is an instance of by
What alternatives are there to property.setvalue()? I've read that it is very slow. I'm using it to map IDataReader to POCO objects. This is a truncated version of the code. Everything here is very new to me. I know there a lot of frameworks that acc
I believe I'm asking a slightly different take on the perennial question of avoiding code repetition. The setup is fairly standard--a bunch of if statements taking similar actions. Below you'll find a short example. I'm trying to figure out the best
Let's say I have an object called thisObject, which may be an int, String, Object, etc., or an array of such classes. I would like the resulting class to be stored in a Class variable called thisObjectArrayClass. This won't compile, but will hopefull
To improve application error handling I would like to log exceptions stack traces and variables values of each stack level. I've searched for Reflection but couldn't find anything. How can I see the variables?Without using additional tools (such as c
I've got to maintain some code written by someone else who is no longer with the company. I'm seeing several references to java.lang.reflect.Array.getLength(anArray). Its working, but I've never seen reflection being used to get an array length. Does
Since Android introduced library projects, I've been converting my app into a library so that I can make several versions with appropriate tweaks (for example, a free and pro version using the same code base, but changing a few things). I initially h
ParameterizedType parameterized = (ParameterizedType) List.class.getMethod("iterator").getGenericReturnType(); Type raw = parameterized.getRawType(); ParameterizedType#getRawType() returns a Type, not a Class<?> (although I get that java.l
How can I get the list of elements and datatypes of an array of an object in c# with reflections? Scenario: I have a method with an array parameter in my web service (asmx). Using reflection I am reading the method parameters and loop through the pro
I have a class like this with a bunch of properties: class ClassName { string Name {get; set;} int Age {get; set;} DateTime BirthDate {get; set;} } I would like to print the name of the property and it's value using the value's ToString() method and
I need to call a function to call user's dll in C#. For example, when user makes a abc.dll with class ABC, I want to load the dll to run the methods xyz(a) in the class. object plugInObject = node.GetPlugInObject("abc.dll", "ABC"); plu
My question in short: how do I detect if a java annotation is present (and in the right place) for a given user class/object. Details of the "problem" Lets say I have two java classes: public class Line { private List<Cell> cells; public L
I have the this method: public function search($searchKey=null, $summary=null, $title=null, $authors=null, $paginationPage=0) { ... } And I'm trying to retrieve all parameters with this: $Class = new Search(); // Get parameters $ReflectionMethod = ne
I have the following class: public class Test { public static int a = 0; public int b = 1; } Is it possible to use reflection to get a list of the static fields only? I'm aware I can get an array of all the fields with Test.class.getDeclaredFields().
I know it is not supported, but I am wondering if there are any tricks around it. Any tips?Reflection in general is a means for a program to analyze the structure of some code. This analysis is used to change the effective behavior of the code. Refle
$0 is the variable for the top level Ruby program, but is there one for the current method?Even better than my first answer you can use __method__: class Foo def test_method __method__ end end This returns a symbol – for example, :test_method. To ret
This is probably best shown with an example. I have an enum with attributes: public enum MyEnum { [CustomInfo("This is a custom attrib")] None = 0, [CustomInfo("This is another attrib")] ValueA, [CustomInfo("This has an extra flag