reflection

Get all the defined functions for an object

Is there an equivalent of get_defined_functions() which only shows the functions of a given object? Example usage and output: class A { function foo() { } function bar() { } } class B extends A { function foobar() { } } $b = new B(); print_r(get_object_functions($b)); // Array ( // 0 => "foo", // 1 => "bar", // 2 => "fo...

Serializing without XmlInclude

Howdie! So I'm deserializing a class called Method using .NET Serialization. Method contains a list of objects implementing IAction. I originally used the [XmlInclude] attribute to specify all classes which implement IAction. But now, I'd like to change my program to load all dlls in a directory and strip out the classes which impleme...

Why is EventInfo.RemoveEventHandler throwing a NullReferenceException?

...

Dynamically loading a class file with a non default package and no nested folders

I am writing a curriculum project for students new to Java. It has a folder structure as so. myjar.jar solutions/my/really/long/package/MySolution.class I got it so the jar can load all classes in the solutions/my/really/long/package/ directory. by adding 'solutions/' to the classpath. My question is if it is possible to set it up so...

Load an ASP.NET 2.0 aspx page using System.Reflection?

Can I load an stand alone aspx page in another stand alone aspx page using System.Reflection? I am using the ASP.NET 2.0 Web site project model. ...

How to pass a function as a parameter in C#?

Is it possible to pass a function as a parameter in C#? I can do it using the Func or Action classes, but this forces me to declare the entire function signature at once. When I try to use Delegate, I get a compile error saying it can't convert a method group to a Delegate. I'm working on Axial and I'm trying to allow users to call web...

Casting to a Class which is determined at run-time

I have a method fetchObjects(String) that is expected to return an array of Contract business objects. The className parameter tells me what kind of business objects I should return (of course this doesn't make sense in this construed case because I already said I will return Contracts, but it's basically the situation I have in my real ...

Is there a way to obtain names of method parameters in Java?

Hello, I'm writing small and very DRY framework, which heavily relies on metadata. I'd like to know if there is a way to obtain method parameter names, i.e. given some method public void a(int myIntParam, String theString) { ... } get the strings "myIntParam" and "theString". I know I could annotate parameters, but that wouldn't be n...

Can I find the file/linenumber where a method was defined?

Duplicate: How To Find Where A Ruby Method Is Defined At Runtime With a given object, is it possible to find out where each method was defined? ...

Class.getConstantPool()

If you decompile the java.lang.Class class in java from the rt.jar library you will notice there is a native method declaration: native ConstantPool getConstantPool(); I played a while ago with class decompilation using Sun's .class file specification and I was able to obtain the constant pool record from each .class file. But that wa...

How do I get the name of a property from a property in C# (2.0)

I know I could have an attribute but that's more work than I want to go to... and not general enough. I want to do something like class Whotsit { private string testProp = "thingy"; public string TestProp { get { return testProp; } set { testProp = value; } } } ... Whotsit whotsit = new Whotsit(); ...

Generic Parse Method without Boxing

I am trying to write a generic Parse method that converts and returns a strongly typed value from a NamedValueCollection. I tried two methods but both of these methods are going through boxing and unboxing to get the value. Does anyone know a way to avoid the boxing? If you saw this in production would you not like it, how bad is it f...

Creating instance of type without default constructor in C# using reflection

Take the following class as an example: class Sometype { int someValue; public Sometype(int someValue) { this.someValue = someValue; } } I then want to create an instance of this type using reflection: Type t = typeof(Sometype); object o = Activator.CreateInstance(t); Normally this will work, however becaus...

C# setting property values through reflection with attributes

I am trying to build an object through an attribute on a classes property that specifies a column in a supplied data row that is the value of the property, as below: [StoredDataValue("guid")] public string Guid { get; protected set; } [StoredDataValue("PrograGuid")] public string ProgramGuid { get; protected set; } In...

In C#, how can I tell if a property is static? (.Net CF 2.0)

FieldInfo has an IsStatic member, but PropertyInfo doesn't. I assume I'm just overlooking what I need. Type type = someObject.GetType(); foreach (PropertyInfo pi in type.GetProperties()) { // umm... Not sure how to tell if this property is static } ...

Figure out the focused control

I'm trying to add a CSS class to the Control that will get the focus, once a page is rendered. While the SetFocus() method of the Page class lets me set the Control, there is no corresponding GetFocus() method. According to the .Net sources, the information is stored in the private member _focusedControl of the Page class. The property ...

.NET Reflection - Finding the type that defines a static member

I have a problem with reflection. I need to find the type that instantiates a static member. My code looks like this: private class SimpleTemplate : PageTemplate { internal static readonly IPageProperty NameProperty = PropertyRepository.Register("Name"); } The PropertyRepository is a repository of prope...

Given an Object, How can I programatically tell what Interfaces it supports?

Given this: Interface IBase {string X {get;set;}} Interface ISuper {string Y {get;set;}} class Base : IBase {etc...} class Super : Base, ISuper {etc...} void Questionable (Base b) { Console.WriteLine ("The class supports the following interfaces... ") // The Magic Happens Here } What can I replace "The Magic" with to display the...

Python : How to check whether a variable is a class or not?

I was wondering how to check whether a variable is a class (not an instance!) or not. I've tried to use the function isinstance(object, class_or_type_or_tuple) to do this, but I don't know what type would a class will have. For example, in the following code class Foo: pass isinstance(Foo, **???**) # i want to make this return True....

In C#, how can I create an instance of an arbitrary Array type at runtime? (.Net 2.0 CF)

I'm trying to deserialize an array of an type unknown at compile time. At runtime I've discovered the type, but I don't know how to create an instance. Something like: Object o = Activator.CreateInstance(type); which doesn't work because there is no parameterless constructor, Array doesn't seem to have any constructor. ...