reflection

C# In Memory Assembly to DLL File

I am trying to save an Assembly to a file using System.Reflection.Emit.AssemblyBuilder but it's not working. I've got a variable to hold an assembly that is running perfect when I load and run it. System.Reflection.Assembly dll = GetAssembly(resource); Is there anyone who can help me to save this "dll" into a file like "name.dll"? ...

RMI + java reflection

I'm using RMI to allow access to my Java application via MATLAB, which runs in another JVM. MATLAB has a nice interface to print the methods of a Java object. But it fails with RMI, because the object it gets is a proxy. So I would like to add my own method to extract/print the capability of a remote interface (RMI obviously can't direc...

How to reflect on C# explicit interface implementation from the call stack?

Is it possible to reflect on an explicit interface implementation from the call stack? I want to use this info to look up an attribute on the interface itself. Given this code: interface IFoo { void Test(); } class Foo : IFoo { void IFoo.Test() { Program.Trace(); } } class Program { static void Main(string[] args) ...

C# - Determine at runtime if property is a Type or an Object instance?

I want to determine whether MyBindingSource.DataSource is assigned to the designer-set Type, or if it has been assigned an object instance. This is my current (somewhat ugly) solution: object result = MyBindingSource.DataSource; if(result.GetType().ToString() == "System.RuntimeType") return null; return (ExpectedObjType) result; ...

Invoking a method of a Generic Class

Here is the Context : I try to code a mapper for converting my DomainModel Objects to ViewModel Ojects dynamically. The problem I get, it's when I try to invoke a method of generic class by reflection I get this error : System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGe...

Failed to create a window when launching it through reflection from the console app

Im trying to launch a dialog by invoking several methods from a windows forms assembly. My app is a console app. All the execution logic goes well and without exceptions, but the window is not launched. Is it a known issue that you cant launch a windows form from a console app? ...

Passing an object and its type to a method

I have three classes: SomeThing, SomeOtherThing, and YetAntherThing. All three have an identical member called Properties. In each class, it is a key/value pair such that I can reference obj1.Name, obj1.Value, obj2.Name, obj2.Value, obj3.Name, and obj3.Value. I'd like to pass these three objects into a single method that could iterate th...

Getting list of fully qualified names from a simple name

I would like to get a list of classes that are available at runtime and that match a simple name. For example: public List<String> getFQNs(String simpleName) { ... } // Would return ["java.awt.List","java.util.List"] List<String> fqns = getFQNs("List") Is there a library that would do this efficiently, or do I have to manually g...

How do I enforce that a class implementing an interface or a subclass extending an abstract class must provide a default constructor?

I have specified an interface (though I can change it to an abstract class if that helps), say T. The users of my API will pass me a Class<? extends T> on which I will call newInstance() (I cannot change that part). How can I ensure that classes that extend T have a constructor which takes no parameter? ...

Find the property's scope within class.

class ParentClass { public function list() { foreach ($this as $property => $value) { if (is_public($this->$property)) echo 'public: '; else if (is_protected($this->$property)) echo 'protected: '; echo "$property => $value" . PHP_EOL; } ...

Determining the Type for a generic method parameter at runtime

Given the a class with the following structure. I am trying to determine the type of the parameter T assigned by the caller of the generic method. public class MyClass{ public <T> Boolean IsSupportable() { Class typeOfT; // Need to determine Class for generic parameter T // Business Logic goes here retu...

Zend framework modules and Reflection

Hello, i'm a bit confused about modules, namespace and reflection. $obj = new default_Model_foo(); $obj->bar(); The code above runs properly, but i need to add reflection; I've got these variables: $moduleName = "default"; $modelName = "foo"; $function = "bar"; I would like to instantiate a class at runtime, how can do it? Tha...

WPF form in a console app

Im running a console app that loads a dll and calls a method from that dll that creates a WPF form. So I'm just calling to Program.Execute() method and it does all the creation of the form. All reflection business goes well, but the form does not appear. I've been told that this is because a console app does not have a windows message ...

Using Reflection to call a function in a dll is not working

Here is the code from the dll: public static bool SendCommand(string command) { KillTeraTerm(); try { SerialPort portToUse = new SerialPort("COM2"); portToUse.Open(); portToUse.WriteLine(command); portToUse.Close(); StartTeraTerm(); ...

using CodeDom to generate an enum with Value as well as Name

Hello, I have this little piece of code : private Dictionary<string, IList<KeyValuePair<int, string>>> EnumsCollection = new Dictionary<string, IList<KeyValuePair<int, string>>>(); // ...... Dictionary is filled, fine // ... outer loop foreach (var enumNameAndValue in EnumsCollection[enumName]) { var code...

Error binding to target method in C#3.0

I am trying to hook Up a Delegate Using Reflection. This is what I have done so far using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Data; using System.Threading; using System.IO; using System.Reflection; using System.Windows; namespace ChartHelper { public class I...

Calling a method inside a .NET 32-bit dll from a .NET 64-bit exe using reflection

I have a 32 bit .NET class library having a simple public class and a simple public method. I have a 64 bit .NET console application where using reflection, I wish to load the 32 bit assembly and consume its method. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using Host....

How can I tell if an object's type is Nullable<T> using reflection?

If I have a Type, is there some easy way to tell that it represents a nullable value type using Reflection? Ideally something a little cleaner (and more correct) than: static bool IsNullable(Type type) { return type.IsValueType && type.Name.StartsWith("Nullable"); } ...

Function to create a tree of properties?

I am trying to create a List of properties for objects. I can create a list for basic objects just fine, but if I have a situation where type object A contains a property of type object B which contains a property of type object A.... well.. then I get infinite recursion. What I've done is added a static property to all of my objects ca...

Is there an elegant way to test if one instance method is an alias for another?

In a unit test I need to test whether alias methods defined by alias_method have been properly defined. I could simply use the same tests on the aliases used for their originals, but I'm wondering whether there's a more definitive or efficient solution. For instance, is there a way to 1) dereference a method alias and return its original...