reflection

How-to get a System.Collections.Generic.List<FieldInfo> list which holds all FieldInfo's of an object of a Type T up to the Object in the class hierarchy in C# ?

I am trying to reuse an existing code ... but with no success . Here is the code snippet: using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Reflection; namespace GenApp.Utils.Reflection { class FieldTraverser { public static string SearchFieldValue(obje...

NonPublic causing a permissions error in reflection on medium trust

I must say that so far, I've probably just been darn lucky in that I've never come across the problems associated with a web site running in medium trust. I've only ever developed intranet apps or happened to have use a hosting company that runs in full trust. But the host I've been asked to use for a recent project runs at medium trust ...

FieldInfo.SetValue vs Type.InvokeMember(fieldName, BindingFlags.SetField)

What is the difference b/w using FieldInfo.SetValue vs Type.Type.InvokeMember(fieldName, BindingFlags.SetField, ...) ? ...

How do you get the Name of the Property

Possible Duplicate: Print property name (not what you would think) Possible Duplicate: Print property name (not what you would think) How do you get the name of the property from the property itself for example theres a property Myproperty and i want to get Name of Myproperty from the property Myproperty, something lik...

Converting GUID to String via Reflection

Hi There, I'm using Reflection to set a property value via PropertyInfo.SetValue(); The property in question is a string, and the object from which I'm getting the value is actually a GUID. I'd like to convert from a GUID to a string in the process - is there any way of defining some kind of implicit cast which will enable this? At the ...

C# MethodInfo getReturnType

I created an instance of MethodInfo: MethodInfo theMethod = typeof(Reciever).GetMethod("methodName", parameterTypes); Now I want to know if theMethod's return type is void. How? ...

Iterating over all properties in a given type in .Net

If I have a complex structure which contains properties which are both simple and complex types, how can I iterate over all the properties of this structure and any child properties which are not simple types? I have a complex type called file, which contains lots of string properties and some which are other complex types which contain...

Using Reflection to find [XmlAttribute("IWantThisValueRightHere")]

I have a class with a few basic properties... [XmlAttribute("MyFirstProperty")] public string FirstProperty { get; set; } [XmlAttribute("MySecondProperty")] public string SecondProperty { get; set; } Using Reflection, I can enumerate through the public properties and get PropertyInfo objects for each of the properties above... the on...

Tool for finding ways to get an object instance inside the debugger?

Right now I'm looking at a bug in some C# code where I need to get a given object instance at some location. I'm sitting on a breakpoint at that location in the debugger and can jump back up the stack and view the object instance that I need to get. I suspect that there is a way to get that instance from what I have (foo.bar.baz.bla.bla....

Reflecting on property to get attributes. How to do when they are defined elsewhere?

I have a class Bar like this: class Foo : IFoo { [Range(0,255)] public int? FooProp {get; set} } class Bar : IFoo { private Foo foo = new Foo(); public int? FooProp { get { return foo.FooProp; } set { foo.FooProp= value; } } } I need to find the attribute [Range(0,255)] reflecting ONLY on the property ...

How do I loop over all the methods of a class in Perl?

How do you loop over all the methods of a class in Perl? Are there any good online references to Perl introspection or reflection? ...

Checking compatibility of two python functions (or methods)

Is there a possibility to check if two python functions are interchangeable? For instance, if I have def foo(a, b): pass def bar(x, y): pass def baz(x,y,z): pass I would like a function is_compatible(a,b) that returns True when passed foo and bar, but False when passed bar and baz, so I can check if they're interchangeable...

What are GeneratedMethodAccessor1,2,etc and why might they not be found?

I'm getting stack traces like this: java.lang.NoClassDefFoundError: sun/reflect/GeneratedMethodAccessor1 at sun.reflect.GeneratedMethodAccessor1.<clinit>(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI...

How to identify abstract members via reflection

Given the follwing class - I would like to know which of the both members is abstract: abstract class Test { public abstract bool Abstract { get; set; } public bool NonAbstract { get; set; } } var type = typeof( Test ); var abs = type.GetProperty( "Abstract" ); var nonAbs = type.GetProperty( "NonAbstract" ); // now, something like...

JavaBeans and DSLs

It's 2009 and we still all hold on the JavaBeans despite all their flaws, mostly because of the tooling support which we wrote in our own blood. But now we have method chaining and internal DSLs and some pressure to replace or extend JavaBeans with DSL classes. Has anyone an implementation that implements PropertyDescriptor for a DSL (w...

Java Reflection and the pain in Refactoring

Java Reflection provides a mechanism to introspect an Object at runtime. No second thoughts, this is a great feature, but it breaks all the Refactoring conventions! There is no easy way (other than File Search) even in modern IDE's to know which attribute is referenced and where. This makes Refactorings much more complex (tiresome!) and...

Improving performance reflection , what alternatives should I consider

Hi, I need to dynamically set values on a bunch or properties on an object , call it a transmission object. There will be a fair number of these transmission objects that will be created and have its properties set in a short space of time.I want to avoid the use of reflection, are there alternativ? If so are there sample implementation...

System.Reflection.Assembly.LoadFile Locks File

I'm loading a DLL via System.Reflection.Assembly.LoadFile and reflecting over it's members in a plugin-esque system. I need to be able to update/overwrite these DLL while the system is running but it appears that after calling System.Reflection.Assembly.LoadFile the file is subsequently locked. Does anyone know of a way to unlock the fil...

Render a View dynamically with UI-related attributes defined in the business entity

I'm using System.ComponentModel.DataAnnotations to give codesmith (using reflection to parse the field-attributes on BE) UI-hints to build my views. But I find DataAnnotations is limited enough. I like something richest, building new custom attributes where one could have more settings to build also complex user interface. I'm too lazy t...

Class object type parameterization in Java

Suppose the following object structure: class Super {} class SubA extends Super {} class SubB extends Super {} I want to be able to have a variable that will hold the class object for either of my subclasses. I feel like this should do it: Class<Super> classObj; Then, I want to be able to something like this: classObj = SubA.cla...