reflection

Find out which classes of a given API are used

In a Java Project of mine, I would like to find out programmatically which classes from a given API are used. Is there a good way to do that? Through source code parsing or byte code parsing maybe? Because Reflection won't be of any use, I'm afraid. To make things simpler: there are no wildcard imports (import com.mycompany.api.*;) anyw...

Java: instantiating an enum using reflection

Hello, Suppose you have a text file like: my_setting = ON some_method = METHOD_A verbosity = DEBUG ... That you wish to to update a corresponding object accordingly: Setting my_setting = ON; Method some_method = METHOD_A; Verbosity verbosity = DEBUG; ... Where all are different kind of enums. I would like to have a generic way to...

Get java.lang.IllegalAccessError when accessing the private field of a outside class via ASM Java Bytecode

Hi, in reflection, the private field can be access via getDeclaredField() and setAccessible(true). How to access the private field of a outside class via Objectweb ASM bytecode API? I set to get the private field from something like, via Field current = sourceObject.getDeclaredField(privateFieldName); Field.setAccessible(true); Type so...

Need help with using reflection for backwards compatability

I've been reading the android documentation on reflection, but i'm just not really grasping how to actually use it. Is it multiple class files i'll have to create? Is it breaking it up to certain parts all in the same class file? I want to understand it, I really do, but I just don't get it. Anyway, I have this simple webview code that...

Databinding and code obfuscation

My employer uses Dotfuscator on all our .Net production software. Because of this, we are absolutely forbidden to use ANY built-in databinding or anything that reflects on property/function names - because dotfuscator changes them and therefore anything bound instantly and irredeemably breaks. I keep rolling this logic over in my mind ...

C# - How to get certain generic types from an assembly using linq

I'm trying to find types in an assembly that are of ISomeInterface< AnyType > using linq. How do I do this? Here's what I have: AppDomain.CurrentDomain.GetAssemblies().SelectMany(a=>a.GetTypes().Where(t=> /* t is ISomeInterface<ofAnyType> */)) ...

automated code review to check if nlog logging is taking place

i have a application written in c#.for the purpose of logging we are using nlog. while performing the code review it was found that people were not logging the required debug and info statements in each method call. What i would like to do is write a small program that will iterate through the assembely and for a particular namespace ...

LINQ to SQL on Dynamic Entity Types?

Trying out a new project with Framework 4.0. I have 2 SQL Server tables with matching DBML entities in my project (EntA and EntB). EntA has a Notes property that maps to a VarChar(50) column. EntB has a NoteText property that maps to a Char(100) column. I have some simple Linq-to-SQL code that prepends the text "* Note: " for each e...

Invoke static type initializers via reflection perhaps

So I have this class public static class MyClass { static MyClass() { ... } } Which has no methods, fields or properties. All it does is wire up handlers to static events defined elsewhere. Since the Type initializer never gets called, because the static class is never actually accessed, the events don't get wire...

How do I deal with arrays using reflection

Hi All, I am writing some validation code. The code will take data passed into a web service and decide whether it can do the action, or return a message to the caller that they have missed out some fields etc. I have it mostly working except for arrays. I am marking up the properties with a [RequiredField] attribute to represent field...

NHibernate 2.1.2 - how to disable reflection optimizer

I want to disable reflection optimization (testing purposes), but i don't know where to do it. NH 2.1.2 uses hibernate-configuration in XML, and docs clearly state that this setting can not be set here. :/ I tried doing it the old App.config way with key/value pairs, no luck ... Also, did NH 2+ version change something about reflection...

QAbstractItemModel for QMetaObject, do I have to write it myself?

A suite of data models built on top of Qt's reflection system seems like a natural synergy, but I haven't found such a beast in the Qt library itself or from a 3rd party. Does anyone know if such a thing exists? I'm look for data models for editing and displaying a collection of QObjects QMetaObject properties. I can kind of understand ...

Access internal field [WebClient]

I have a WebClient instance that receives data from a remote website. I referenced a DownloadProgressChanged event handler and I am trying to access InnerBuffer, which is an internal field in the DownloadBitsState nested class (set as private) in WebClient. I am using the following code right in the DownloadProgressChanged event handler...

Error invoking an extension method using reflection

I am getting an InvalidOperationException with the message: "Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true." The following is the relevant part of the code: // Gets the entity type of the table to update. Type entityType = Jobs.GetType(syncSettings.TableToUpdate); // Creates...

Enumerate ICollection<T> property of class using Reflection

I'm trying to create a base class for my POCO objects in .NET 4, which will have an Include(string path) method, where path is a "." delimited navigation path of nested ICollection properties of the inheriting class to be enumerated. For example, given the following classes; public class Region { public string Name { get; set; } ...

C# struct instantiation at runtime.

Could anyone provide an example how to create a structure instance at runtime? The structure I'm using doesn't define any constructors, just fields. The GetConstructor() method returns null, and so far I was unable to find a way to achieve this. ...

Reflection on Properties for highest level one

class CBase { object A {get;set;} object B {get;set;} } class CDerived : CBase { object X {get;set} object Y {get;set;} } I'm trying to get first level properties. For the example above, intended properties are X and Y, not A and B. With the following code i'm getting all the properties {A,B,X,Y}. Is there any solution without att...

how to restrict invoke method

I wonder if there is a way to restrict invoke call to a function? Let me make it clear. [Assembly:a1] Class A { function Af(); } [Assembly:a2] Class B { function Bf(){ //load Assembly a1 //InvokeMember to Af } } After compilation I will have 2 assemblies. Now if I distribute to client, anyone can copy assembly...

c# lambda expression + reflection questions

This is mostly for educational purposes. I'm trying to create the InputMapper class, which is used in this example: var mapper = new InputMapper<SomeType>(); mapper.Map("some user input", someType => someType.IntProperty, "Input was not an integer"); mapper.Map("some user input", someType => someType.BoolProperty, "Input was not a bool"...

Comparison Operator using Reflection

I want to compare two values at runtime using reflection. I was using Comparer.Default.Compare(x,y) for this, but I have come to realize that this is not adequate. Let's say I want to compare a double to a single (1.0 == 10). Comparer.Default will throw an exception because it insists that both values must be the same type (double). Howe...