I have a class in Java, I wish to reflect all subclasses of this class, how would I do this?
In this specific case, all subclasses are in the same package, and only subclasses are in this package, so an equivalent solution is to fetch all classes in a package.
...
In my business layer, I need many, many methods that follow the pattern:
public BusinessClass PropertyName
{
get
{
if (this.m_LocallyCachedValue == null)
{
if (this.Record == null)
{
this.m_LocallyCachedValue = new BusinessClass(
this.Database, this.Pro...
I'm writing a little utility to load Entity Data Models from an assembly and query against them.
I've tried using Reflection to load a derived ObjectContext, but ObjectContext doesn't derive from MarshalByRefObject so I can't pass parameters to the constructor with Activator.CreateInstance() (according to the exception I get.)
Is it ...
I was just reading http://stackoverflow.com/questions/25458/how-costly-is-reflection-really
I do numerous reflection calls for property sets and was wondering if I should be looking at converting all of my PropertyInfo.SetProperty() into MethodInfos calls so that I can run Delegate.CreateDelegate against.
Finally if I do this, I assume ...
In both my NUnit SetUp and TearDown methods, I need to retrieve the MethodInfo of the test that is about to be run or has been run. Is this possible? I'm using NUnit 2.5.
Motivation: I would like to be able to retrieve, via Reflection, attributes attached to the test method.
...
Hello
Assuming I have an event subscription such as
_vm.PropertyChanged += OnViewModelAmountChanged;
How can I see that method name by reflection the way you can see it in the debugger? I got as far as the line below before I decided I might be in the Twilight Zone
?vm.GetType().GetEvent("PropertyChanged").EventHandlerType.GetMethod...
I'm looking for more generic/"standard" way to instantiate object of some type T from set of pairs string,object. For me it looks like there should be some well known way to do it but I cannot find it, so I come up with this piece of code.
Does anybody know something better?
// usage
public class test
{
public int field1;
p...
In order to define a method in C that is callable by Lua it has to match a given signature and use the Lua API to retrieve parameters and return results. I'm writing a C# wrapper of Lua and I'm interested in being able to call arbitrary C# methods without making them follow these conventions. When wrapping in something like D, one might ...
I am trying to write some code that will allow me to dynamically load DLLs into my application, depending on an application setting. The idea is that the database to be accessed is set in the application settings and then this loads the appropriate DLL and assigns it to an instance of an interface for my application to access.
This is m...
MVC2 comes with a nice sample of a validation attribute called "PropertiesMustMatchAttribute" that will compare two fields to see if they match. Use of that attribute looks like this:
[PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public class ChangePass...
Using reflection, is it possible to discover all types that derive from a given type?
Presumably the scope would be limited to within a single assembly.
...
Hi folks,
i'm wondering if it is possible to programattically recurse up a stack trace to a particular assembly.
I'm using StructureMap and it creates an instance of a particular class, to inject into another class. kewl. When i'm in the constructor of the injected class, i wish to see what was the parent class and the stack trace more...
Hi - I have a large number of C# WCF services that are being called by an enterprise system. When we encounter issues during development it can take a long time to reproduce the exact conditions on our development machines. Essentially we need to log the request using WCF & build an integration test based on the data logged. If the ob...
I am trying to use reflection to check if properties on a given class have a ReadOnly attribute set. The classes I am using are MVC View Models (using a partial "buddy" class for the metadata.
public partial class AccountViewModel
{
public virtual Int32 ID { get; set; }
public virtual decimal Balance { get; set; }
}
[...
First, an example of something that works as expected: (all code was executed in VS2008 immediate window)
25 is IComparable
>> true
25.GetType().GetInterfaces()
>> {System.Type[5]}
>> [0]: {Name = "IComparable" FullName = ...
>> [1]: {Name = "IFormattable" FullName = ...
>> ...
So far so good. Now let's try on an object where t...
Is it possible to find all interfaces (classes, parameters, ect..) normally registered with Component Object Model's (COM) TypeLib even though the TypeLib is completely empty? If so how would you go about doing this? I believe another term for this is an "Anonymous COM". I am sure that accessible interfaces exist for this COM because i ...
I have a webpage in ASP.NET 3.5 that will be creating WebControls dynamically. The WebControls that it will be creating will be known by their fully qualified path (ie - System.Web.UI.WebControls.whatever). The reason for this is because I am allowing the user to decide what controls will go on the webpage. Of course, there's more comple...
For instance, I have a class called "My_Class_X123.java" like this :
public class My_Class_X123 // This file was generated by a java program
{
static String ABC[]={"1","2",...};
int XYZ=0;
}
When I wrote my program I didn't know there would be a class by this name, but at run time I found out a class by the name of "My_Class_X1...
In this question a user replied that he was able to override the security settings on a shared host. I'm using the same host, but haven't been able to figure out how to change web.config to allow reflection. Is it a one-liner?
I'm using MVC + Nhibernate in my project, but I can't even get an Mvc "new project" template site to work, I su...
Hi everybody. I'm trying to use reflection for some reason and I got into this problem.
class Service
{
public int ID {get; set;}
.
.
.
}
class CustomService
{
public Service srv {get; set;}
.
.
.
}
//main code
Type type = Type.GetType(typeof(CustomService).ToString());
PropertyInfo pinf = type.GetProp...