reflection

OpenGL render vs. own Phong Illumination Implementation

Hello: I have implemented a Phong Illumination Scheme using a camera that's centered at (0,0,0) and looking directly at the sphere primitive. The following are the relevant contents of the scene file that is used to view the scene using OpenGL as well as to render the scene using my own implementation: ambient 0 1 0 dir_light 1 1 1 ...

how to I get the class name when I am passing in a generic in my method?

My method looks like: public string DoObjectProperties<T>(T obj, string text) { } Now from within the method, I need to get the string value of the class name that i pass into the method's 'obj' parameter. So if I pass in the User object, I need the text 'user'. To get the properties I am using: typeof(T).GetProperties() How can I...

Getting Nested Object Property Value Using Reflection

I have the following two classes: public class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } } public class Employee { public string FirstName { get; set; } public ...

Library development - looking for valid use cases for suggested feature

I'm contributing to a library called Fasterflect whose purpose is "improving the developer experience of using reflection". As such, it provides an abstraction built on top of classic reflection and would be used in exactly the same scenarios. The following shows the current syntax for accessing members via an object instance: obj.SetP...

What is the best way get and hold property reference by name in c#

I want to know if there is a better way (than what I'm currently doing) to obtain and hold a reference to a property in another object using only the object and property string names. Particularly, is there a better way to do this with the new dynamic functionality of .Net 4.0? Here is what I have right now. I have a "PropertyReferenc...

Using a Type object to create a generic

Hello all! I'm trying to create an instance of a generic class using a Type object. Basically, I'll have a collection of objects of varying types at runtime, and since there's no way for sure to know what types they exactly will be, I'm thinking that I'll have to use Reflection. I was working on something like: Type elType = Type.Get...

Calling MethodBase's Invoke on a constructor (reflection)

Hi everyone. First of all, sorry if this has been asked before. I've done a pretty comprehensive search and found nothing quite like it, but I may have missed something. And now to the question: I'm trying to invoke a constructor through reflection, with no luck. Basically, I have an object that I want to clone, so I look up the copy co...

Instructing a generic to return an object of a dynamic type

This question is sort of a follow-up to my original question here. Let's say that I have the following generic class (simplifying! ^_^): class CasterClass<T> where T : class { public CasterClass() { /* none */ } public T Cast(object obj) { return (obj as T); } } Which has the ability to cast an object into a s...

Java Reflection Utility

Is there a utility to get a property which isnt prefixed by get from an object using reflection similar to BeanUtils? e.g. if I specify "hashCode" and I want to get the object.hashCode() value. Thanks. ...

How to find out if an object's type implements IEnumerable<X> where X derives from Base using Reflection

Give a base class Base, I want to write a method Test, like this: private static bool Test(IEnumerable enumerable) { ... } such that Test returns true if the type of o implements any interface of IEnumerable<X> where X derives from Base, so that if I would do this: public static IEnumerable<string> Convert(IEnumerable enumerable) { ...

checking whether a package is existent or not

How can i check whether a package like javax.servlet.* exists or not in my installation of java? ...

Java - Get a list of all Classes loaded in the JVM

Hi all, I would like to get a list of all the classes belonging to a certain package as well as all of their children. The classes may or may not be already loaded in the JVM. Walter ...

C# Reflection - Casting private Object field

I have the following classes: public class MyEventArgs : EventArgs { public object State; public MyEventArgs (object state) { this.State = state; } } public class MyClass { // ... public List<string> ErrorMessages { get { return errorMessages; } ...

How do I get the type argument of a generic type?

i think this is a simple question but I've searched around and can't seem to find an answer easily. if you have var list = List<int>(); ... fill list ... and you want to get the generic type in list, i realise you could just type: var t = list.FirstOrDefault().GetType(); Is there another way to do this via just the list, rather th...

Casting of object for a class loaded at runtime

hi, i load a class using Class.forName(klassname,false,loader) After this i create an instance using klass.newInstance(); It returns an object type.I want to cast it to specific type(ie.Klassnamw instance).I used normal casting but it gets hung because it is not resolved during runtime.How can i cast it?Hellp ...

How to simply a foreach iteration using reflection

Consider that I have to get the overall performance of X. X has Y elements and Y in turn has Z elements which inturn has some N elements. To get the performance of X I do this: List<double> XQ = new List<double>(); foreach (Elem Y in X.Y){ List<double> YQ = new List<double>(); foreach (Elem Z in Y.Z){ List<double> ZQ = new L...

How to get MinValue/MaxValue of a certain ValueType via reflection?

I need to this at runtime. I checked using Reflector and value types line like Int16, for example, should contain <Serializable, StructLayout(LayoutKind.Sequential), ComVisible(True)> _ Public Structure Int16 Implements IComparable, IFormattable, IConvertible, IComparable(Of Short), IEquatable(Of Short) Public Const MaxValue As Sh...

Reflection in Ruby. Instantiate an object by given class name

I came to ruby from PHP. How could i do the next thing in ruby? $className = 'ArrayObject'; $arrayObject = new $className(); Thank you for any help! ...

Execute method with Action<T> argument using Reflection

How can i create a Action method to use as a argument to the following function? public void When(Action<T> action) { if (internalValue != null) action(internalValue); } I have the MethodInfo on the method, and the parameter type like so: var methods = value.GetType().GetMethods(); MethodInfo mInfo = methods.First(method...

Dynamically Run IQueryable Method

Hi! I'm trying to run the Count() function of a Linq statement in an overriden Gridview function. Basically, I want to be able to assign a linq query to a gridview, and on the OnDataBound(e) event in my new extended gridview have it retrieve the count, using the IQueryable. So, I need to dynamically cast the GridView.DataSource to my L...