reflection

How would you implement basic reflection in C++?

I'm thinking about adding some sort of reflection capabilities to some C++ classes ( so that I wouldn't have to use RTTI ): getting names of methods, declared fields, class name ... this sort of stuff. I was thinking about parsing existing source files, get a list of declared fields & methods, and rewrite each source file, adding this s...

What Performs Worse: Reflection or Boxing?

I'm working on creating my own DI framework that creates delegate factories as a learning exercise. My way of building typed delegates is to use expressions to create a function that calls a static method with reference to my container and any constructor params. This thrown up an interesting question with regards to value types. Whic...

Improve property monitoring code?

Hey folks, I made a utility debug class in a C# game I'm working on to be able to monitor and watch values of properties. Goes like this: public static class Monitor { private static List<object> monitoredObjects; public static void Initialize() { monitoredObjects = new List<object>(); } public static void Watch(object ...

Can a transient field in a class be obtanied using reflection

Can a transient field in a class be obtained using reflection? (using getDeclaredField(..)) ...

Getting information about a member invoked using Type.InvokeMember()

I'm using Type.InvokeMember() to dynamically invoke various members of a Type. Since the members can be generic and also include out parameters etc., I'm happy to have the runtime handle this. However, I also need to have additional information about the actual member that's been invoked -- particularly, the return type. If this type ...

Howto find out if a field is instanceof a type via reflection?

I want to find out via reflection if a field is an instance of some type T. Lets say I have an object o. Now I want to know if it has any fields which are instance of T. I can get all fields with: o.getClass().getFields(); I can get the type of the field with: field.getType(); But now I want to know if this type or any supertype ...

How can I generate Virtual Properties with the AssemblyBuilder in C# 4.0?

I'm currently working on creating an Assembly with virtual properties. The examples on MSDN are only creating normal properties. How do I create a class inside an assembly which has virtual properties? I would like to be able to generate a class like this: public class ClassA { public virtual int Id { get; set; } ...

How to create inheritance based serialization mechanism?

Hey everyone, I whould like to creat a serialization mechanism, to work on a variety of entities, all of which are based on a few base-classes. Now I want to work with DataContractSerializer, so I need to mark all my classes with [DataContract]. but I dont want to do that because that is a big room for error for other members of my tea...

How do I GetConstructors via the Class Name?

Hello, I have this program which gets all the constructors from the mscorlib using a search function. The only problem is when I search for the constructors it will only filter ctor. This is a problem because the search is no use if it's constantly going search all files relating to ctor (which is all files). I'm displaying both the de...

Get private Properties/Method of base-class with reflection

With Type.GetProperties() you can retrieve all properties of your current class and the public properties of the base-class. Is it somehow possible to get the private properties of the base-class too? Thanks class Base { private string Foo { get; set; } } class Sub : Base { private string Bar { get; set; } } Sub s = ...

How to get string type for nullable types

I'm generating a T4 template using the properties of my data class generated from my dbml files. To get the property type of the classes I use item.PropertyType.Name, the problem is that with nullable types it returns Nullable `1, is there a way to get Nullable<int> for example, or int?? ...

Finding the name of a particular property of a class from within the class in C# 3.5

Give a class like below, how can i find the name of one particluar property? public class Student { public int Grade { get; set; } public string TheNameOfTheGradeProperty { get { return ???? } } // More properties.. } So i would like to return the st...

Java Reflection Property String name ->Class Datatype

Is there a way to specify the String name of a property in a particular bean and return the class that the getter corresponds to? ...

Create an object whose type is in a string parameter

I have a TreeView, which contains nodes. When a user clicks on a node, corresponding CrystalReport document should be created and displayed. For example, names of my nodes are: "PeriodReport1", "PeriodReport2", "PeriodReport3". My CrystalReport documents are named same: "PeriodReport1", "PeriodReport2", "PeriodReport3". How can I creat...

Java: getting inner type in nested parameterized types (reflection)

Most of the documentation regarding type erasure handling in Java assumes that the use case is handling a type like SomeType<ParamType>. I am trying to process method parameter for the following method: public void setOtherReferenceRanges(List<ReferenceRange<T>> referenceRanges) When the container class is instantiated with a type DvQ...

Clear .Net Reflection cache

When doing dynamic compiling of C# source code, if we happen to try to execute a compiled target DLL (for example tmp901.tmp.dll) that has a missing reference, for example: *InnerException: Could not load file or assembly '_O2_Scanner_MsCatNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.* There se...

C# Generics - Find correct concrete class depending on object type

I have my domain model with several NewsType's which are subclasses of NewsItem as shown below (simplified): public abstract class NewsItem : Entity { public virtual Account Account { get; set; } public virtual DateTime DateTime { get; set; } } Here are a couple of subclasses of NewsItem: public class NewsItemJoiner : NewsIte...

Is it possible to retrieve file info via reflection in C#?

Say you've got a MethodInfo, or any other sub-class of MemberInfo for that matter, in C#. Is it possible to retrieve the name of the file it was declared in and possibly the line numbers for where the declaration starts? This information has to exist somewhere in the debug-mode metadata since creating an instance of StackTrace will give ...

Loading a generic type by name when the generics arguments come from multiple assemblies

I need to create a type from its full name only Ex: "System.String" or "Tuple'2[string,Mytype]". there is no information about the assembly in the string. Here is what the code look like. private static Type LoadType(string typeName) { // try loading the type Type type = Type.GetType(typeName, false); if (type != null) ...

java.security.AccessControlException: access denied using Java Web Start

I am having some issues with accessing files using JWS (Java Web Start). The program adds a new label and image. The program runs fine on my local computer but gives me pages of errors when I run the program on my remote server using JWS. Here's a sample of the error: Exception in thread "AWT-EventQueue-0" java.security.AccessControl...