reflection

How can I determine the file name that is being executed in a mono C# environment when the file was created with mkbundle2?

When running a C# application under mono with the "mono " command, the following works: var fileName = System.Reflection.Assembly.GetExecutingAssembly().Location; But after packaging the assemblies into a single file using mono's mkbundle2, the line above does not return the expected result. ...

Assembly.GetTypes() for nested classes

Assmbly.GetTpes() gets the types in the assembly but if I also wants nested class (OrderLine) how do I do that? I only know the name of the assembly, not the class names so GetType(Order+OrderLine) will not work. public class Order { public class OrderLine { } } ...

Reflection using path strings in .NET

Is there any way to using reflection in .net to get a property's value using a path like so... type t { id : int name : string } type s { id : int st : t { let a = {id = 1; {id = 2; name = "foo"}} a.getType().getProperty("st.name") Sorry for the F#. This doesn't work obviously but it illustrates what I'm trying to ...

Is there a java reflection API around the java.lang.reflect package?

A lot of Java projects use reflection. I wonder if is there a reflection library which make the use of java.lang.reflect easier. We could use it like: Reflected object = new Reflected( new Object() { String name="Oscar"; String lastName="Reyes"; String reverseName(){ return new StringBuilder(nam...

Load different COM files with same names (older versions) from different paths in C#

Hello, i need to build a program that load older versions of a COM DLL file and performs some operations. I've created a DLL project for each version and set the reference to the correspondent COM. After that in the main program i'm trying to load the needed assembly that load and use itself its COM. The problem is that the DLLs have Int...

Reflection in C#: How do I get the calling method name and type?

Hello :) I'd like to write a method which obtains the name of the calling method, and the name of the class containing the calling method. Is such a thing possible with C# reflection? Billy3 ...

Determine at runtime if a cast is allowed (C#)

I have a C# wraper class with a series of methods accepting various data types: public class MyClass { public void ProcessString(string Value) { // implementation } public void ProcessInt(int? Value) { // implementation }\ public void ProcessOther(MyClass Value) { // implementation } } I now want to add a generic ProcessOb...

How to create a delegate for a reflected method at run time

I want to create a Delegate of a reflected method, but the Delegate.CreateDelegate requires the Type of delegate be specified. Is it possible to dynamically create a 'Delegate' that matches whatever function is reflected? Here is a simple example: class Functions { public Functions() { } public double GPZeroParam() ...

How Jersey extracts generic type from Collections to invoke javax.ws.rs.ext.MessageBodyWriter#writeTo()?

In a Rest Service using the JAX-RS specification, I can define a generic service like @GET @Path("something") @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public List<MyPojo> getMyPojoList() { ... } Something magic happens in Jersey because when invoking javax.ws.rs.ext.MessageBodyWriter#writeTo(T t, ...

what is reflection in C#, what are the benefit. How to use it to get benifit

I was reading an article at msdn about reflection but i was not able to understand it even 10% about its benifit, its usage. Could you please provide some brief overview what is reflection and how can i take benefit from it. ...

Porting code from Reflection to using an Interface, some API's not implemented.

I have some old C# plugin code that was implemented strictly with Reflection. In fixing some C# 2.0 -> 4.0 compatibility issues ("Load from Remote Source") I've decided to get rid of the old reflection code and replace it with an interface. The interface is needed because the Plugins now need to be loaded into their own AppDomain and t...

How to load an arbitrary java .class file from the filesystem and reflect on it?

I want to make a command-line utility that does some operations based on reflection of external class files. I would pass in a path to .class files or source files(possibly wildcards). At some point during the execution, I need to get Class objects for each class, not knowing their package names beforehand. What would it take to do th...

ICustomAttributeProvider.GetCustomAttributes(...): Design Strangety?

The MSDN Documentation: MemberInfo.GetCustomAttibutes Method (Type, Boolean) states in the remarks: This method ignores the inherit parameter for properties and events. To search the inheritance chain for attributes on properties and events, use the appropriate overloads of the Attribute.GetCustomAttributes method. This basically m...

Generate DynamicMethod from MethodInfo

I was going over a Joel Pobar's Dodge Common Performance Pitfalls to Craft Speedy Applications article on Reflection and I was looking at a particular piece of code that isn't compiling (slightly modified to narrow down to the specific error, because his example had more errors): MethodInfo writeLine = typeof(Console).GetMethod("WriteLi...

Detect a code fragment from looking at a binary

Without working on the source, just on the basis of a binary, is there a way (there sure must be using CodeDom, but it'll be nice if it is possible without CodeDom) to tell if a method's body has an if construct, using reflection? ...

Load the code DOM from a binary

Is it possible to load the CodeDOM from a .NET binary created using C#? ...

Distinguish between the type used to reference an object and the type of its backing store

using System; interface IAnimal { } class Cat: IAnimal { } class Program { public static void Main(string[] args) { IAnimal cat = new Cat(); // Console.WriteLine(cat.GetType()); // This would only give me the type of // the backing store, i.e. Cat. Is there a // way I can get...

Is it possible to decompile the whole .NET application?

I know that .NET apps are difficult to protect. I use RedGate Reflector and know that generally speaking you can get source code from many .NET dlls. however my question is - is it actually feasible to decompile the whole application? I mean - create a workable VS solution so the pirate can just press F5 and get the exactly same result...

Can I inject few line of my code into someone elses .NET dll ?

I want to replace one line of code in 3d party API with my own code. I mean this is questionable practice but I need to fix their bug (the idiots call ResolveDNS on every method call which writes to TCP socket - what they were going to achieve with it?) which results in untolerable lags. I want to cache DNS name in static field and scr...

Python: Convert args to dict, like PHP's compact?

I want a function exactly like PHP's compact function. i.e., if I pass in a list of variable names: compact('var1','var2') it returns me back a dict: {'var1':var1, 'var2':var2} ...