reflection

Java: Setting array length for an unknown number of entries

I am trying to fill a RealVector (from Apache Commons Math) with values. I tried using the class's append method, but that didn't actually add anything. So now I'm using a double[], which works fine, except I don't know in advance how big the array needs to be. private void runAnalysis() throws IllegalArgumentException, IllegalAccessExc...

How to convert variable name to string in c#.net?

public new Dictionary<string, string> Attributes { get; set; } public string StringAttributes = string.Empty; public int? MaxLength { get; set; } public int? Size { get; set; } public int? Width { get; set; } public int? Height { get; set; } protected override void OnInit(EventArgs e) { Attributes = new Dictionary<string, string>()...

Java "settings object", serialization/deserialization

(Code is for Android Actually, I need code to be portable between Android and Java SE.) I want to have a "settings" class with various game settings, like public int map_size; public String server_name; etc. The data needs to be accessed fairly frequently (so members, not a key-value map), and from time to time de/serialized in some...

Get list of classes in namespace in C#

I need to programmatically get a List of all the classes in a given namespace. How can I achieve this (reflection?) in C#? ...

How to get properties from FieldInfo in C#?

Hello, I have this method and want to get all properties from the FieldInfos? How to get it? private static void FindFields(ICollection<FieldInfo> fields, Type t) { var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var field in t.G...

Load and modify AS3 SWF

Is it possible to load an ActionScript 3 SWF and interact with it, for example by replacing some of its functions or editing variables? Similar to how it's possible in .NET using reflection and code generation. I'm looking to add an extra layer of functionality over an existing 3rd-party AS3 app. ...

Is there an effective way to determine whether .Equals on two different but "equal" instances will return true?

I'm attempting to use reflection to determine the result of a call to .Equals on two different but "equal" instances of a type. My method would be something like: public static bool TypeComparesProperties(Type t) { // return true if (an instance of t).Equals(a different instance of t) // will be true if all publicly accessible...

List all concrete or abstract classes of object

Is it possible in C#, via reflection or some other method, to return a list all superclasses (concrete and abstract, mostly interested in concrete classes) of an object. For example passing in a "Tiger" class would return: Tiger Cat Animal Object ...

Execution-time performance of code in class created using reflection versus a 'normal' class.

Is the execution time (run-time) performance of code in a class that is loaded via reflection identical to the same code when the class is created using the new keyword? I say yes. But I was discussing this with a colleague who believes that the reflection oriented code is always slower. My view is that regardless of how the class wa...

How can I dynamically create and save a LINQ-to-SQL object via reflection?

The following method creates a linq-to-sql object at run time based on a class name. I can also fill the properties of the item via reflection. But how do I save this object via the linq-to-sql commands if I don't know at runtime which type it is? public void CreateItem(string className) { //create instance of item string cla...

Using Reflection to get a variable's name

I'm using MVVM and within one of my VM's I have an IsEditable property (well they all do from a base class) which is used by a series of buttons to determine whether their commands can fire. This VM also has a sub VM for which I need to echo this IsEditable property down to, currently I'm overriding my OnPropertyChanged method to check ...

Call a function based on JVM version.

I have a JFrame object, and i need to support two JVM 1.5 on Mac OS X and 1.6 on Windows. On windows I need to use setIconImages function to set multiple icon sized for the application but this function is not availible on 1.5. Is it possible to call this function inside JFrame with reflection? Application extends JFrame{ . . . void i...

Can objects created with .net reflection be serialized?

Is it possible to serialize an object that is created through reflection? I get an error of "Unable to cast object of type 'testNameSpace.ScreenClass' to type 'testNameSpace.ScreenClass'" when attemping to perform the serialization of the object that was created through reflection. The error does not make sense since the types are ident...

A method that executes any time a class property is accessed (get or set) ?

C# - .net 3.5 I have a family of classes that inherit from the same base class. I want a method in the base class to be invoked any time a property in a derrived class is accessed (get or set). However, I don't want to write code in each and every property to call the base class... instead, I am hoping there is a declarative way to "si...

Java equivalent of Ruby ObjectSpace.each_object

I'm looking for a way to get all instantiated objects of a given type in Java. With Ruby you can use the ObjectSpace.each_object method: a = 102.7 b = 95.1 ObjectSpace.each_object(Numeric) {|x| p x } would give 95.1 102.7 ...

How do you use .net Reflection with T4?

Hi all, I have a c# project which includes a Text Template. I would like this template to generate some SQL based on reflecting against the C# classes in the project. How does one access the current project's contents using T4? Is it possible, and if so, is Reflection available, or is it access to just the raw source that must then be ...

Getting a list of accessible methods for a given class via reflection

Is there a way to get a list of methods that would be accessible (not necessarily public) by a given class? The code in question will be in a completely different class. Example: public class A { public void methodA1(); protected void methodA2(); void methodA3(); private void methodA4(); } public class B extends A { public v...

Is this possible in C#?

I have an extension method for testing so I can do this: var steve = new Zombie(); steve.Mood.ShouldBe("I'm hungry for brains!"); The extension method: public static void ShouldBe<T>(this T actual, T expected) { Assert.That(actual, Is.EqualTo(expected)); } This shows: Expected: "I'm hungry for brains!" But was: "I want to shu...

Unable to find class annotation

Why does this code print 0? @Table(name = "source") public class SourceDetails implements DatabaseEntity{ public static void main(String[] args) { System.out.println(SourceDetails.class.getAnnotations().length); } ... } ...

In 3 minutes, What is Reflection?

Many .Net interview question lists (including the good ones) contain the question: "What is Reflection?". I was recently asked to answer this in the context of a 5 question, technical test designed to be completed in 15 minutes on a sheet of blank paper handed to me in a cafeteria. My answer went along the lines of "Reflection allows you...