Get the type of the generic type fullname

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

How to check if a state object is of type ICollection

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

Iterate via struct by variable name

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

Find all imported interfaces supported by the object

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")

Call method with parameters via JSON in Java

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

F # comparing unions discriminated by case identifier

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

Create an instance using the base constructor

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

Can C # constraints be used without a basic type?

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

Given a collection get the type of elements (Java)

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 = (

C # List all methods in a control

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

Check if the java.lang.reflect.Field type is an array of bytes

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

Alternatives to using property.setvalue () for efficiency

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

Move in similar repetitions in if statements

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

How can I get the .class value of a class array?

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

.NET - Trace the print stack with variables

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

java java.lang.reflect.Array.getLength vs array.length

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

Calling non-library code from an Android library

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

Read items from an array of objects using C # reflection

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

C # Print Properties

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

Implementing the PlugIn function with C #

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

Add null values ​​to a table

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

Recover only the static fields declared in the Java class

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().

C reflection support

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

Get the name of the running method

$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