reflection

C# working with decorated members

Take this class for example: public class Applicant : UniClass<Applicant> { [Key] public int Id { get; set; } [Field("X.838.APP.SSN")] public string SSN { get; set; } [Field("APP.SORT.LAST.NAME")] public string FirstName { get; set; } [Field("APP.SORT.FIRST.NAME")] public string LastName { get; set; } ...

C#: Reflecting enum name

Let's say I have this class: public class SiteMapEntry { public static enum ChangeFrequency { Always, Hourly, Daily, Weekly, Monthly, Yearly, Never } } And this function: public class FooBar(SiteMapEntry.ChangeFrequency changeFreq) { } Which is called: string f...

What is the most efficient performance-wise way of associating information with a 'Type' object in .Net?

I want to associate custom data to a Type, and retrieve that data in run-time, blazingly fast. This is just my imagination, of my perfect world: var myInfo = typeof(MyClass).GetMyInformation(); this would be very fast... of course this does not exist! If it did I would not be asking. hehe ;) This is the way using custom attribute...

Reflecting derived classes in C#

Let's assume there's a class with a virtual property (let's call it 'P'). It's overridden in a deriving class. Now I want to use something like this: obj.GetType().GetProperty("P") to get info about the overriding property. This search is ambigous, because there are two "P" properties (base and override). So I typed: obj.GetType().GetPr...

Python grab class in class definition.

I don't even know how to explain this, so here is the code I'm trying. from couchdb.schema import Document, TextField class Base(Document): type = TextField(default=self.__name__) #self doesn't work, how do I get a reference to Base? class User(Base): pass #User.type be defined as TextField(default="Test2") The reason...

Is there a way to get the list of InnerClasses through Reflection in Java?

Is there a way to know the inner classes that a Class has through Reflection in Java? ...

How do I get a Type[] with arguments from a MethodCallExpression?

I'm reflecting over a class (in a unit test of said class) to make sure its members have all the required attributes. To do so, I've constructed a couple of helpers, that take an Expression as an argument. I do some checks for it, and take slightly different actions depending on what type of Expression it is, but it's basically the same....

Add folder, which contains java sources, to classpath at runtime

Is it possible to add a folder which contains java source code as a classpath element. I have tried a few things and it seems that the classloadr is not picking up java soruce files? One of my attempts is shown below.... File uncompressedSrc = new File("uncompressed" + File.separator + "src" + File.separator); URL uncompressedSrcURL = n...

Check if field type is same as generic type in java

I want to determine if a field is typed as the subclass of a generic type. For e.g Foo extends Bar<Foo> Foo x; How do I tell if the field x is typed as a subtype of Bar<Foo>? ...

C# Reflection and Getting Properties

I have the following dummy class structure and I am trying to find out how to get the properties from each instance of the class People in PeopleList. I know how to get the properties from a single instance of People but can't for the life of me figure out how to get it from PeopleList. I am sure this is really straightforward but can ...

Get property name from class

I need property name in my app and I use next code to get it string PropertyName =SomeClass.GetType().GetProperty("Category").Name; But I think that is bad idea. Because I use web service classes and I dont know when property names can be changed. This code give me exception only in runtime. But if I write something like this SomeCla...

set value of a property of an anonymous type using reflection / TypeDescriptor is it possible ?

I tried using TypeDescriptor and the value is not changing, and via reflection I get an error that there is no setter for that property ...

NoSuchMethodException while using JAVA Reflection

Hi I'm trying to use reflection to invoke a method and update the setter value of that method. But I'm getting NoSuchMethodException while ivoking that method. I've updated the code. I'm so sorry for the errors in the previous code. I've refractored the code. The exception occurs when the setMethod of the class accepts primitive type arg...

ASP.NET MVC security: how to check if a controller method is allowed to execute under current user's perrmissions

Given an ASP.NET MVC Controller class declaration: public class ItemController : Controller { public ActionResult Index() { // ... } public ActionResult Details() { // ... } [Authorize(Roles="Admin, Editor")] public ActionResult Edit() { // ... } [Authorize(Roles="Admi...

Invoke method using Reflection on COM Object

Hi, I have an instance of a COM object ... which is created like this.. Type type = TypeDelegator.GetTypeFromProgID("Broker.Application"); Object application = Activator.CreateInstance(type); when i try to invoke a method : type.GetMethod("RefreshAll").Invoke(application, null); -> type.GetMethod("RefreshAll") returns null. When ...

Reliably finding annotations on class loaded with URLClassLoader

I have a code generator that uses URLClassLoader to load classes on a specified path, scan them for annotations, and then using Reflection on the fields/methods, generate DTOs. It works great, in the test app. When I put it into the Maven MOJO, I suddenly lose the ability to see the javax.persistence.Entity annotations on the classes....

How can I invoke a method on an object using the Reflection API?

How do I invoke a method (e.g. setter inside object class) on an already existing object using Java reflection? ...

Programmatically access the CIL for a .NET type

Is there a straighforward library that I can use to access the CIL for a .NET type? Let me demonstrate what I want the fictitious CilExtractor to do: [Serializable] public class Type_For_Extract_Cil_Test { private int _field = 3; public int Method(int value) { checked { return _field + value; } } } [Test] public ...

How to dynamically use the PropertyType reflection attribute to create a respective typed Function<>?

I want to use type returned by PropertyType to create a typed function. I found this similiar http://stackoverflow.com/questions/914578/using-type-returned-by-type-gettype-in-c but this mentions how to create a list but does not mention how we can create a Func<>. Please help me out. Pseudocode: PropertyInfo inf = typeof(SomeClass).Get...

Finding all classes containing a method in C#

I want to search through all classes in a namespace for those containing a certain method. If a class contains a method then I want to create an instance of the class and run the method. Obviously I have to start with reflection but I'm stuck on where to go. Edit: Interfaces are not the way I want to do this. What I'm looking for is...