reflection

Is it possible to see via which child class was a parent's static method called in Java?

A little background first. I am looking into the possibility of implementing Ruby's ActiveRecord in Java as cleanly and succinctly as possible. To do this I would need to allow for the following type of method call: Person person = Person.find("name", "Mike"); Which would resolve to something like: ActiveRecord.find(Person.class, "na...

.NET Reflection of all method parameters

Is it possible to get the parameter name (where I have parmName below)? Or perhaps in the MSIL code there are only relative positions, no absolute parm names? I have an unusualy case using HIP within Microsoft Host Integration Server. When fields are NULL and the error goes back to CICS (on the mainframe), the error is "A CALL TO VERI...

Detect Silverlight version required by an assembly

How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required? I have all information that is available through reflection (Mono.Cecil). Same question for SL 3 versus 4. Thanks in advance. ...

c# gettype of object from class

How could I make this work?: public class myClass { public string first; public int second; public string third; } public string tester(object param) { //Catch the name of what was passed not the value and return it } //So: myClass mC = new myClass(); mC.first = "ok"; mC.second = 12; mC.third = "ko"; //then would return its type...

How do I get all the instance variables of an object without using its getter methods?

I have POJO class Class Book { private String id; private String title; Public Book() { } //implement setter and getter .............. } main() { Book book = new Book(); book.setId(1); book.setTitle("new moon"); } How to get all instance variable of book object I want the result become -> 1, "new moon" without using the getter m...

COM Interop in .NET

I have a C# Visual Studio 2008 project and I want use a COM interop XXXXLib (XXXX.dll). Of course I have to add reference to %windir%\system32\xxxx.dll before, and VS will add Interop.xxxx.dll to the project folder, and now I have to distribute this 200 KB library with my simple 4 KB application. But, now I know that PCs don't have XXX...

It's there a way to invoke a generic methodInfo?

It's there a way to invoke a method and the return type is strong typed ? There is an example of code public static IQueryable<T> FilterVersion<T>(this Table<T> t, IVersionIndexFilter version) where T : class { try { // Define the new type of my table Type versionTableType = Type.GetType(typeof(T)...

C# getting value of parms using reflection

How can I get the values of parms (in a loop using reflection). In previous question, someone showed me how to loop through the parms using reflection. static void Main(string[] args) { ManyParms("a","b","c",10,20,true,"end"); Console.ReadLine(); } static void ManyParms(string a, string b, string c, int d, short e, bool f, s...

Validation of .NET assemblies in C#?

How do you check if a assembly loaded is a valid .NET assembly? I currently have this code but unmanaged DLL's throw a BadImageFormatException. string[] filepaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories); List<Type> potentialEffects = new List<Type>(); foreach (string f...

How can I determine the type of a generic field in Java?

I have been trying to determine the type of a field in a class. I've seen all the introspection methods but haven't quite figured out how to do it. This is going to be used to generate xml/json from a java class. I've looked at a number of the questions here but haven't found exactly what I need. Example: class Person { public fina...

How can I instantiate WPF elements via their type when they have StaticResources?

I need to instantiate WPF types (say, a UserControl or a Page) via reflection for a designer. The problem I'm having is that when I attempt to instantiate these using Activator.CreateInstance I get a TargetInvocationException which wraps, in the end, an exception thrown by the StaticResource markup extension. Clarification: The types ...

Answering "Which method called me?" at the run-time in .NET? Or is CallStack data readable by the code?

Presume that there are methodA() , methodB() and methodC(). And methodC() is called at the run-time. Is is possible to know methodC() is called from what method? I was thinking if CallStack can be read at the run-time for some checks? If yes, I think it should not be a big deal. Any ideas? Thanks! ...

Dynamically Load Assembly and manually force path to get referenced assemblies

Hi I am loading an assembly in C# using reflection: Assembly = Assembly.Load([assembly_bytestream]); The assembly being loaded references another two assemblies. To my understanding reflection will load the main assembly and then search the GAC for the referenced assemblies, if it cannot find it there, you can then incorparate an ass...

.NET 3.5 Reflection Help

Sup Guys, On my Bussiness Layer, I have something like Dim object as New ExampleObject Where ExampleObject inherits BaseExampleObject. I want to know how can I access ExampleObject Properties by reflection on my BaseExampleObject. Something like: MyBase.GetType.GetProperty("PropertyName").GetValue(mybase.gettype, Nothing) Of cou...

Is it possible to make the transition from F(Type) to F<T> without reflection and without a dictionary?

Dear sirs and ladies. First, a little introduction. I have to functions: static class C { static void F1(Type type) { // Do something to invoke F2<T> } static void F2<T>() { // bla bla bla } } I wish to invoke F1(Type), which in turn should transition to the generic context pertinent to the given type parameter a...

How to convert the current class name of asp.net usercontrols to string on c#?

So I have tried GetType() but for some reason, It does include the namespace... Does C# not have a property for a class specifying its name? For example: public class Parent : System.Web.UI.UserControl { public someFunction(){ Child child = new Child(); Console.WriteLine(child.ThePropertyThatContainsTheName); } }...

Pass method, created with reflection, as Func parameter

Hello, I've got a method (fyi, I'm using c#), accepting a parameter of type "Func", let's say it's defined as such: MethodAcceptingFuncParam(Func<bool> thefunction); I've defined the function to pass in as such: public bool DoStuff() { return true; } I can easily call this as such: MethodAcceptingFuncParam(() => { return Do...

Finding and invoking a generic overloaded method

How can I find a generic overloaded method? For example, Queryable's public static IQueryable<TResult> Select<TSource , TResult> ( this IQueryable<TSource> source , Expression<Func<TSource , int , TResult>> selector ); I've looked for existing solutions, and they're either not generic enough (are based on the method's parameters count...

Loading a .NET 3.5 assembly via reflection in .NET 2.0

I have an interesting situation and am trying to do something that I'm not even sure is possible. I have a .NET 2.0 project that via reflection loads an assembly, and calls a specific method on that assembly. We are looking at moving forward and starting to use .NET 3.5 in the environment, but want to minimize risk with regard to this ...

Parameter converted from null to DateTime.MinValue when called using Invoke in C# 2.0

I have code a bit like this public class MyObject { private bool IsValidDay(ref DateTime theDate) { ... } } MethodInfo[] methods = myObjectInstance.GetType().GetMethod("IsValidDay", BindingFlags.Instance | BindingFlags.NonPublic); object[] args = { null }; bool val = (bool)method.Invoke(myObjectInstance, args); But ...