reflection

free tool to generate class diagram or method table from a C# assembly or project?

Is there a free, easy and quick tool which can generate class diagrams or maybe even a simple table containing the list of class and methods inside an C# assembly or a project? Basically what I need is just the list of class and methods in a readable format. It would be better if it takes the xml documentation as well, but it's not requi...

C#, WPF - setting alignment property by reflection with a string value

Hi, I'd like to set align property (horizontal/vertical) of an object through reflection, with a value of type string. I use something like private void SetPropertiesFromString(object nav, string properties) { Regex r = new Regex("(?[^~]*)~(?[^]*)"); MatchCollection mc = r.Matches(properties); Type type = nav.GetType(); ...

How can I call default(T) with a type?

In c# I can use default(T) to get the default value of a type. I need to get the default type at run time from a System.Type. How can I do this? E.g. Something along the lines of this (which doesn't work) var type = typeof(int); var defaultValue = default(type); ...

Get Oracle PL/SQl variable property by name (reflection in PL/SQL)

Hi, I need to do some auditing on updating a row. So I have a function that receives a parameter of type some_table%ROWTYPE, containing the new values to be saved for that row. I also need to save some info in a history table regarding what column values where changed. I was thinking of getting the column names for some_table from all_...

How to identify what state variables are read/written in a given method in C#

What is the simplest way to identify if a given method is reading or writing a member variable or property? I am writing a tool to assist in an RPC system, in which access to remote objects is expensive. Being able to detect if a given object is not used in a method could allow us to avoid serializing its state. Doing it on source code ...

Programmatically compare IL of two methods

I have a compiled assembly. I want to programmatically compare the method implementation of one of the methods in that assembly with something I expect. Is there a way I can compare their ILs? Even if I can get a byte array representation of any instruction set, I'll be in a good place. Help appreciated. ...

InvokeMember call is throwing MissingMethodException

I am invoking one of the functions from assembly but I am getting MissingMethodException. I have open exe in .netreflector and show that function is available at right place though it is giving error. Here is the code. private void button2_Click(object sender, EventArgs e) { Assembly obj = Assembly.LoadFrom("Solo4O.exe"); ...

Capturing Inline Expression Result

What I need to do is capture the result of an expression within an MVC view (sample below). I have also provided a stub Processor demonstrating what I want to achieve. Basically I want to divert the Target of the Action into some arbitrary string buffer that I can manipulate later. However the Target property is readonly. Can this ...

java reflection

Does anyone knows what is the different between: Class clazz = getClass().getClassLoader().loadClass(className); AND Class clazz = Class.forName(className); As i tried both, it gave me same result. ...

How do I invoke HasValue on a nullable property of an object via reflection?

...

Null reference check required to enumerate a collection inside a reflected assembly?

I'm running into a very strange behavior in C#/.NET 3.5... I am writing a class which hooks into upload pipeline of a content management system. The CMS executes this hook via reflection. For some unknown reason the following code fails by throws a NullRef ("Files" is an HttpFileCollection). foreach (var fileKey in args.Files.AllKeys...

How to get the class contained by a Vector - Reflection

Hi, I'm using QDox to parse a .java file. The file contains a method like this: public int getSomething (Vector<Integer> numbers); the problem is I don't know how to get the Integer class using the reflection which QDox provides. Any idea of how can I get it? ...

How to use Class.cast() properly?

Hey all, I have a Command class like the following: public class Command { ... private String commandName; private Object[] commandArgs; ... public void executeCommand() {} } I also have a subclass of Command, AuthenticateCommand: public class AuthenticateCommand extends Command { ... @Override public...

Using PropertyInfo to find out the property type

Hi All, I want to dynamically parse an object tree to do some custom validation. The validation is not important as such, but I want to understand the PropertyInfo class better. I will be doing something like this, public bool ValidateData(object data) { foreach (PropertyInfo propertyInfo in data.GetType().GetProperties()) { ...

Using LINQ to find the class that is in the bottom of the inheritance chain

Given a sequence of assemblies with classes eg. AssemblyA Customer AssemblyB Customer : AssemblyA.Customer AssemblyC Customer : AssemblyB.Customer Given the name (not taken care of namespace) Customer, can I use LINQ to query against the sequence of assemblies to find the customer at the bottom of the inheritance cha...

Dynamically list all members of a class

Hi, Is it possible in C++ to dynamically (during run-time) get a list of all members of the class? Greetings ...

How can I programmatically change the argspec of a function in a python decorator?

Given a function: def func(f1, kw='default'): pass bare_argspec = inspect.getargspec(func) @decorator def func2(f1, kw='default'): pass decorated_argspec = inspect.getargspec(func2) How can I create a decorator such that bare_argspec == decorated_argspec? (As to why, the framework that calls the decorated function does argsp...

Using extension methods with runtime assemblies

Is there any way to use extension methods on a class that has been dynamically created using Relection.Emit? For example: class somewhere { somewhere() { // define the type here using ReflectionEmit, etc. Type tableType = CreateTableType(...table parameters...); var table = Activator.CreateInstan...

OpenGL CubeMap rendering from desktop instead of environment

This is weird, and I can't find anything like it online. I am rendering a reflective sphere in OpenGL, and I'm trying to reposition the camera and use glCopytexImage2D to render directly to the Cube Map textures. Problem is, my reflective sphere ends up reflecting everything on my desktop EXCEPT the OpenGL environment! How does something...

Legacy API requires to pass callback name as string. Can I improve that API via an extension method?

I'm faced with a legacy API that doesn't use .NET events, but rather requires me to do this: // (first arg is System.Object, second arg is string, myFoo is of type Foo) myFoo.AddCallback(this, "DoSomething(int)"); This API requires that DoSomething be an instance method on this, and that it take an int. Is there a way I can use force...