reflection

Use an interface from an external assembly that's marked as "internal" (C#)

I'd like to implement an interface that resides in an external assembly. However that particular interface has been marked as "internal". Is there a way I can still implement this interface for my own classes? I know how to call private/internal methods using reflection in C#, so I guess reflection should be used in this case too. Howev...

Can I find out if a particular attribute was present on the calling function?

Is there a way to find out if the calling function had attributes set on it? [RunOnPlatformB] int blah() { return boo(); } int boo() { // can i find out if RunOnPlatformB was set on my caller? } ...

Compare two objects with same data

I wanna to compare two objects, for example: DirectoryInfo di1 = new DirectoryInfo("C:\\"); DirectoryInfo di2 = new DirectoryInfo("C:\\"); OK, yeah I know we have here different reference, this class doesn't implement IComparable, and even GetHashCode is returning the different results. But they are the same! (logically:)) I know ...

Use BuildManager.GetType to look through assemblies in WPF

I have existing code for an ASP .NET application that uses reflection to load dataproviders. I would like to re-use this code in a WPF application but it appears that BuildManager.GetType only looks through top level assemblies if the app isn't ASP .NET. Does anyone know how to get around this limitation? The following code throws an ex...

From FullyName string to Type object

Anyone know how to get a Type object from a FullName? Eg. string fullName = typeof(string).FullName; Type stringType = <INSERT CODE HERE> Assert.AreEqual(stringType, typeof(string) ...

Invoke static initializer

Once a class is loaded is there a way to invoke static initializers again? public class Foo { static { System.out.println("bar"); } } Edit: I need to invoke the static initializer because I didn't write the original class and the logic I need to invoke is implemented in the static initializer. ...

Load assembly and change source, is it possible and how?

I'm writing .NET On-the-Fly compiler for CLR scripting and want to implement next idea: there is a template file with C# code, I want to read it, create an assembly, load it and amplify source on-the-fly. How can I do that? ...

Eclipse RCP: ClassNotFoundException or How to make other bundle load my class.

details: I'm trying to use Jalapeno framework to connect my RCP app with Cache' database. After connection established, I'm trying to get all data from table exactly like in Jalapeno manual: if (objManager==null) return; DBClass cortege = null; try { Iterator terms = objManager.openByQuery(DBClass.class, null, null); System.out.println(...

C#: Accessing Inherited Private Instance Members Through Reflection

I am an absolute novice at reflection in C#. I want to use reflection to access all of private fields in a class, including those which are inherited. I have succeeded in accessing all private fields excluding those which are inherited, as well as all of the public and protected inherited fields. However, I have not been able to acc...

Is there a way to ease the pain of maintaining .NET assembly references?

I'm currently working on a web project that involves several assemblies, structured something like this: WebProject | +--> A (external assembly, Version 1.0.0.0) | +--> B (external assembly, Version 1.0.0.0) The difficulty is that in order to keep track of what's deployed, I'd like to updated the version numbers of assemblies A an...

How do I create a generic class from a string in C#?

Hello ... I have a Generic class like that : public class Repository<T> {...} And I need to instance that with a string ... Example : string _sample = "TypeRepository"; var _rep = new Repository<sample>(); How can I do that? Is that even possible? Thanks! ...

NHibernate proxies prevent Castle.Validator component to do it's job

Hello, everyone! I've run into the problem with NHibernate proxy validation using Castle.Validator component. It's looks like validator could not fetch attributes from entity proxy's properties. I've tried to define validation attributes using Inherited = true while Castle.Validator runner fetch em using following statement: property....

How to include source code location information (file/line/column) in .NET assembly?

I need to be able to get from .NET assembly a class/struct/interface definition location (filename,begin_line,begin_column,end_line,end_column) in my source files. First solution that came to my mind was using some pdb quering api, but it seems that I can obtain such info only for method definition this way. Or maybe I'm wrong... To pr...

Given the names of the types as strings, how would I construct a generic using reflection?

Presuming I have the strings "List" and "Socket," how would I go about creating a List<Socket>? The answer I need will work just as well for Queue and XmlNodeList, not to mention MyCustomGeneric with MyCustomClass. ...

Quick question on reflection in C#

I am getting started with the notion of test-driven development, and kind of failing since I am finding that I know what the test is going to be kind of, but I can't figure out how to get it to do what I want. What I have is a property that has a public getter and an internal setter. I'd like to test the functionality by accessing the ...

Finding dead PHP5 classes/methods

Is there any tools to check for dead code for PHP5? Something like Scan classes with Reflection Follow "normal" code with token_get_all() and find variables with token T_NEW and then scan for method calls. Output something like classname (count of new declarations) methods (count of calls) ...

Problem using ChartArea.Select method

I am trying to select the ChartArea using the Select method through reflection in C#. This is the line of code I am using: oChartArea.GetType().InvokeMember("Select", BindingFlags.InvokeMethod, null, oChartArea, null); Here, oChartArea is the ChartArea object. This works perfectly fine in Vista/Office 2007 but throws exception in XP...

How to distinguish between a function and a class method ?

If a variable refers to either a function or a class method, how can I find out which one it is and get the class type in case it is a class method especially when the class is still being declared as in the given example. eg. def get_info(function_or_method) : print function_or_method class Foo(object): def _...

Determine Correct Method Signature During Runtime

I am using the following the following class org.apache.poi.hssf.usermodel.HSSFCell, with a list of the following methods: void setCellValue(boolean value) void setCellValue(java.util.Calendar value) void setCellValue(java.util.Date value) void setCellValue(double value) void setCellValue(HSSFRichTextString value) void setCellValue...

How to find all the classes which implement a given interface?

Under a given namespace, I have a set of classes which implement an interface. Let's call it ISomething. I have another class (let's call it CClass) which knows about ISomething but doesn't know about the classes which implement that interface. I would like that CClass to look for all the implementation of ISomething, intanciate an inst...