reflection

Capturing method state using Reflection

Is there a way to use .NET reflection to capture the values of all parameters/local variables? ...

Accessing internal members via System.Reflection?

I'm trying to Unit Test a class that has many internal functions. These obviously need testing too, but my Tests project is seperate, mainly because it covers many small, related projects. What I have so far is: FieldInfo[] _fields = typeof(ButtonedForm.TitleButton).GetFields( BindingFlags.NonPublic | BindingFlags.Instance ...

What is Reflection?

I am VERY new to ASP.NET. I come from a VB6 / ASP (classic) / SQL Server 2000 background. I am reading a lot about Visual Studio 2008 (have installed it and am poking around). I have read about "reflection" and would like someone to explain, as best as you can to an older developer of the technologies I've written above, what exactly ...

How can I find the method that called the current method?

When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod(), but I want to go one step beneath this in the stack trace. I've considered parsing the stack trace, but I am hoping to find a cleaner more explicit way, something like Assembly.GetCa...

Creating an instance from a class name

I'm trying to create an instance of a class at run time. The classes I'm trying to create all inherit from a base class, ConfigMgrObj, and are named ConfigMgr_xxxxxx e.g. ConfigMgr_Collection. They all take a special object that I'm calling oController and a string as arguments. This is the line I'm using to do it, where ClassToGet is a...

How does WCF deserialization instantiate objects without calling a constructor?

There is some magic going on with WCF deserialization. How does it instantiate an instance of the data contract type without calling its constructor? For example, consider this data contract: [DataContract] public sealed class CreateMe { [DataMember] private readonly string _name; [DataMember] private readonly int _age; priva...

Getting a System.Type from a type name

I want to get a System.Type given only the type name in a string. For instance, if I have an object: MyClass abc = new MyClass(); I can then say: System.Type type = abc.GetType(); But what if all I have is: string className = "MyClass"; ...

Dynamically find the class that represents a primitive Java type

I need to make some reflective method calls in Java. Those calls will include methods that have arguments that are primitive types (int, double, etc.). The way to specify such types when looking up the method reflectively is int.class, double.class, etc. The challenge is that I am accepting input from an outside source that will specify...

Create Generic List from a subclass

Option Explicit On Option Strict On Public Class Class1 Dim l As List(Of A) Public Sub New() l = New List(Of B) End Sub End Class Public Class A End Class Public Class B Inherits A End Class<p> I've run into this problem. I have a list declared of a Generic Type 'A' I want to define the list as a Generic T...

Instantiating a JavaScript object by calling prototype.constructor.apply

Let me start with a specific example of what I'm trying to do. I have an array of year, month, day, hour, minute, second and millisecond components in the form [ 2008, 10, 8, 00, 16, 34, 254 ]. I'd like to instantiate a Date object using the following standard constructor: new Date(year, month, date [, hour, minute, second, millisecond...

Reflection.Net: how to load dependencies?

I try to add an addons system to my Windows.Net application using Reflection; but it fails when there is addon with dependencie. Addon class have to implement an interface 'IAddon' and to have an empty constructor. Main program load the addon using Reflection: Assembly assembly = Assembly.LoadFile(@"C:\Temp\TestAddon\Addon.dll"); Type ...

How to test whether method return type matches List<String>

What is the easiest way to test (using reflection), whether given method (i.e. java.lang.Method instance) has a return type, which can be safely casted to List<String>? Consider this snippet: public static class StringList extends ArrayList<String> {} public List<String> method1(); public ArrayList<String> method2(); public StringList...

java.beans.Introspector getBeanInfo does not pickup any superinterface's properties

I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example: public interface Person { String getName(); } public interface Employee extends Person { int getSalary(); } Introspecting on Employee only yields salary even though name is inherited from Person. Why is this? I wo...

How to read assembly attributes

In my program, how can I read the properties set in AssemblyInfo.cs: [assembly: AssemblyTitle("My Product")] [assembly: AssemblyDescription("...")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Radeldudel inc.")] [assembly: AssemblyProduct("My Product")] [assembly: AssemblyCopyright("Copyright @ me 2008")] [assembly:...

How do I tell if a class property has a public set (.NET)?

I have this: public string Log { get { return log; } protected set { if (log != value) { MarkModified(PropertyNames.Log, log); log = value; } } } And my utility class for databinding ...

Method parameters value through Reflection

I am trying to log a method's parameters by using reflection. I read the earlier question posted about this issue on StackOverflow as well which pointed me to CLR API's. Is it possible, someone can point me to the right direction, as to how will I get the values of parameters passed using API? ...

.NET Dynamic Objects with Reflection

How do I determine if a Nullable(of Enum) is indeed an Enum by means of reflection? I'm working with a method that dynamically populates an object of type T with an IDataReader retrieved from a database call. At its essence, it loops through the datareader's ordinals, and all the properties of T and populates the properties that match ...

What sorts of things should I do to make a performant and robust reflection cache?

In .NET 3.5, I'm going to be working with System.Reflection to use AOP (probably in the context of Castle's Windsor Interceptors) to do things like define which security actions need to be performed at the method level, etc. I have heard that some parts of Reflection are slow (I've read the MSDN article around it), and would like to cac...

Assembly not saving correctly

I have some very simple code to generate an assembly and invoke a method on a contained type. The method gets called and runs correctly, however when I view the generated assembly using Reflector, I don't see the type. Below is the sample code: namespace ConsoleApplication2 { class Proggy { public static void Main(string[...

Call and Callvirt

What is the difference between the CIL instructions "Call" and "Callvirt"? ...