reflection

Pitfalls in getting memeber variable values in Java with reflection

I have an abstract class as follows. I want to get all the values of member variables. public abstract class PARAMS { public static final String NAME1 = "VAL1"; public static final String NAME2 = "VAL2"; public static final String NAME3 = "VAL3"; } The values are retrieved using reflection as follows. Field[] fields = P...

Is this considered reflection and to what degree?

I have an Android application (java) that was working fine when compiled with the Android 1.6 SDK using the following code from the android.provider.Contacts class: Uri baseUri = Contacts.Phones.CONTENT_FILTER_URL; When the 2.0 SDK came out, the android.provider.Contacts class was depreciated and replaced with android.provider.Contact...

Setting a value through reflection is not working.

I am trying to set a value through reflection. I created this little test program struct headerIndexes { public int AccountNum{ get; set; } public int other { get; set; } public int items { get; set; } } static void Main(string[] args) { headerIndexes headers = new headerIndexes(); ...

How do I get the PropertyInfo.PropertyType name of a EntityReference type via reflection

I am writing a small code generator which would read into an edmx file and create business objects on the base of a template. I am using reflection to spit out the type names. The problem is when I encounter a property (PropertyInfo) of type Entity Reference, (basically an entity property if there is a referential integrity), the Proper...

Reflect a list value into another list?

List <ClassA> listA; List <ClassB> listB; Can I use reflection to reflect listA into listB? I got below code but only reflect an object public static <A, B> B convert(A instance, Class<B> targetClass) throws Exception { B target = (B)targetClass.newInstance(); for (Field targetField : targetClas...

java.lang.NoSuchFieldException: when using reflection

public static <A, B> B convert(A instance, Class<B> targetClass) throws Exception { B target = (B)targetClass.newInstance(); for (Field targetField : targetClass.getDeclaredFields()) { targetField.setAccessible(true); Field field = instance.getClass().getDeclaredField(targetField.getName())...

How are variables bound to the body of a define_method?

While trying to brush up my Ruby skills I keep running across this case which I can't figure out an explanation for by just reading the API docs. An explanation would be greatly appreciated. Here's the example code: for name in [ :new, :create, :destroy ] define_method("test_#{name}") do puts name end end What I want/expect to...

Delegate for an Action< ref T1, T2>

I'm trying to create a delegate of a static method which takes a ref argument. Please don't ask why I'm doing such a cockamamie thing. It's all part of learning how .Net, C#, and reflection work and how to optimize it. My code is: public struct DataRow { private double t; static public void Cram_T(ref DataRow...

Creating a Structure from a string in C#

I've seen a lot of questions asked about instantiating classes from a string but have been unable to find any information on creating a structure the same way. I have a class which contains a structure like so: Public Structure callDetails Public GUID As Guid Public ringTime as Date Public CBN As String etc. All I really...

Building delegate handler collection

I have an implementation building a delegate handler collection. public class DelegateHandler { internal delegate object delegateMethod(object args); public IntPtr PublishAsyncMethod(MethodInfo method, MethodInfo callback) { RuntimeMethodHandle rt; try ...

Allow or disallow method run in .NET

Hi! I need to organize some simple security in a class depends on value of the enum. All that I can figure out is using attribute on a method and then run check then if it fails throw an exception. Sample: [ModulePermission(PermissonFlags.Create)] public void CreateNew() { CheckPermission(); System.Windows.Fo...

vb.net reflection vs. late binding?

What should be more proper or what is recommended to use in VB.NET from either reflection vs. late binding: 'Type can be various objects that have a common property for sure.' Dim type = sender.GetType() Dim prop = type.GetProperty("Text", 20) Dim value = property.GetValue(sender, Nothing) versus: Dim value = sender.Text ...

Adding an item to an ObservableCollection of an unknown type

I'm creating a WPF application using the MVVM design pattern, and I'm trying to create a Combobox that allows the user to edit the items in the drop-down list at runtime, similar to the way MS Access 2007 lets you do it. So I've created a UserControl that builds on top of a Combobox... when the drop-down is shown, there is a button belo...

Reflection attacks in Auth protocol

Hi all, I have come across a theory on Auth protocol hacking vulnerability which can be found in http://www.owasp.org/index.php/Reflection_attack_in_an_auth_protocol. I understand how this vulnerability causes problems in exchanging the messages and how to bypass validation to become a logged-in and to be a valid user. The following co...

When catching a general exception, how can I determine the original exception type?

When catching an exception in .net, you can have as many type-specific exception blocks as needed. But I usually try to have at least one "general" exception catch block. But is there a way to get the type of the "real" exception thrown that is caught by the generic exception handler, perhaps using reflection? For example, if I have C...

Need a Better Way Than Reflection

I'm reading a CSV file and the records are recorded as a string[]. I want to take each record and convert it into a custom object. T GetMyObject<T>(); Currently I'm doing this through reflection which is really slow. I'm testing with a 515 Meg file with several million records. It takes under 10 seconds to parse. It takes under 20 sec...

Java introspection and reflection

Can any one explain the use of Java reflection and introspection? When we need to use both? ...

Get type from GUID

For various reasons, I need to implement a type caching mechanism in C#. Fortunately, the CLR provides Type.GUID to uniquely identify a type. Unfortunately, I can't find any way to look up a type based on this GUID. There's Type.GetTypeFromCLSID() but based on my understanding of the documentation (and experiments) that does something ve...

File level configuration? C# and Reflection?

I have a file with a dozen classes and i use reflection to generate data from it. I was thinking it may be cool if i had a way to configure all of the classes in that file at once. How might i do this? -edit- everyone seems confused. I posted a possible solution below. I want to attach data to a file. While using reflection i would lik...

Find a specific class in a file using reflection?

I googled and someone found the answer and linked but it was dead. How can i find a specific class in a specific file? The poster i found ask that question and found how to do it in a namespace but i would like to find one specific to a file. This question is to answer my other question but now that i thought of this i would like to know...