reflection

How to raise PropertyChanged event without using string name

It would be good to have ability to raise 'PropertyChanged' event without explicit specifying the name of changed property. I would like to do something like this: public string MyString { get { return _myString; } set { ChangePropertyAndNotify<string>(val=>_myString=val, value); } ...

C# Reflection : how to get an array values & length ?

Hi, I have that code: FieldInfo[] fields = typeof(MyDictionary).GetFields(); MyDictionary is a static class, all fields are string arrays. How to get get the Length value of each array and then itearate through all elements ? I tried the cast like: field as Array but it causes an error Cannot convert type 'System.Reflection.FieldI...

how can i evaluate generic type in runtime in c#

i need to evaluate generic type at runtime using Type.GetType() Type t = Type.GetType("className"); Table<t> table = dataContext.GetTable<t>(); any ideas please ?? ...

Use reflection or a property when unit testing?

This is a class I'm a bit concerned about. My goal is to unit test the addresses list: public class LabelPrinter { private readonly IEnumerable<Address> _addresses; public LabelPrinter(IEnumerable<Address> addresses) { _addresses = addresses; } public Document Create() { // ... Generate PDF, etc...

GWT Server-side reflection

I am trying to use Reflection on the server side only of a GWT app. I have a basic example working in a non-GWT example which can be seen below. package com.xyz.reflection; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class EntryPoint { /** * @param args */ public static void main(Stri...

Java: NoSuchMethodException when method clearly exists

On my current project, I've felt the need to create a sort of simulated callback system in Java using reflection. However, I'm having issues getting my reflection to actually function. The code at fault follows: public Callback(Object parentObj, String methodName, Class<?>...parameters) { if(parentObj == null) throw new Ille...

Trying to use Reflection to Invoke Method within same class

I have a WCF service that accepts an object as a parameter that has a URI and Method Name. What I am trying to do is have a method that will look @ the URI, if it contains the words "localhost" it will use reflection and call a method, of the name that is passed in as a parameter, within the the same class, return a value and continue on...

AS3, Getting the class in which some method is defined.

Hello everyone, In ActionScript 3. Given some method! Is there a way to get the class that's defining my method (at runtime). Furthermore the method is static. Looked at http://www.as3commons.org/ but doesn't seem to find what I'm looking for. ...

Members of object not being returned by PropertyInfo c#

I'm trying to use PropertyInfo interate through a class and create a datatable from it. However it returns no values. I'm a little stumped; public class thetransactions { public string FirstName; public string Surname; public string PreviousOwner; public string NewOwner; public string postcode; public string[] ...

Unboxing and Reflection in Java?

I have a method with the signature public void setFoo(int newFoo) in a model I'm writing. I'm using the following code to call it from within my controller: protected void setModelProperty(String propertyName, Object newValue) { for (AbstractModel model: registeredModels) { try { Method method = model.getClass(...

Reflecting specific property types from subclasses

I have a large class with many nested subclasses of different types as follows: class BigFooClass { // Classes Foo InnerFoo {get; set;} Bar InnerBar {get; set;} Oof InnerOof {get; set;} Rab InnerRab {get; set;} // Simple Properties Decimal OuterDecimal {get; set;} Long OuterLong {get; set;} { Each of t...

how to use reflection in C# to list the methods of an .asmx

given a url that references an asmx how would i go about displaying all of their method names? if assembly="http://.../something/something.asmx" and i was trying to display the method names of that service what should i do now that i have gotten myself this far? i cant seem to find a solution among the hundreds of examples ive looked at...

C# Expensive method calls ? Assembly.GetEntryAssembly() and Assembly.GetCallingAssembly()

I just saw this line of C# code and I am wondering if it is expensive Assembly assembly = useEntryAssembly ? Assembly.GetEntryAssembly() : Assembly.GetCallingAssembly(); ...

How to Optimize this method

private static void ConvertToUpper(object entity, Hashtable visited) { if (entity != null && !visited.ContainsKey(entity)) { visited.Add(entity, entity); foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties()) { if (!propertyInfo.CanRead || !propert...

How to print values of an object in Java when you do not have the source code for the class?

public class MyClass { ClassABC abc = new ClassABC(); } I just have a .class file of ClassABC. I want to print all the public, private, protected and default field values of "abc" object. How can I do this using Reflection? ...

set multiple properties simultaneously via reflection

Hi. I'm trying to optimize the reflection utilization in my code and I was wondering whether it's possible to set multiple properties of the object at once: Sample usage: private void SetProperties<T>(List<T> objects, List<Tuple<string, object>> propsAndValues) where T:Task { Type type = typeof(T); var p...

BuildManager.GetType on the Compact Framework ( resolving a class name at runtime on all appdomain )

Hi! Is there any way to search for a Type with only its type name in all application domain on the Compact Framework 2.0? Type.GetType's behavior needs one to specify the assembly name on where to look. BuildManager.GetType does exactly that, but it isn't available for the CF. While this would be fine if I could call AppDomain.CurrentDo...

Is reflection secure?

I'm experimenting with PropertyChangeSupport which has the useful firePropertyChange method. If security is a concern, is it actually safe to use reflection to trigger methods as in the line below or would it be preferable to simply hardcode calls to method names? If reflection is a potential issue, how would one prevent it? method.invo...

Is there a way to enumerate all properties in a vb6 class module?

In .Net you can use reflection to get access to an enumeration of all properties of a class. Can this be done too with a VB6 class module? ...

Iterate through Object's own Strings & Trim each

I have multiple large objects which each have about 60 strings. I have to trim all those strings, and I'd like to do so without having to go this.mystring = this.mystring.Trim(). Instead, I'm looking for a way to automatically have each object discover its own strings and then perform the operation. I know a little bit about reflection,...