reflection

Determine property calls between two classes in .Net

Given two .Net types, type A and type B, how could one determine all property calls to type A (including sub classes of type A) made from type B? ...

How can I scan MSIL code to find certain function calls

Hi all, I am to build a SOA gui framework, and I'd like to autodetect services, and service dependencies from client modules. I have code such as this so far, which works using attributes, placed on class modules: [ServiceProvider(typeof(DemoService3))] [ServiceConsumer(typeof(DemoService1))] I am wondering how I can scan for these a...

LINQ (or anything) to add items from an objects list to the objects row in a datagrid?

Say the object is as follows: string Name Dictionary<string,bool> Tags Where tags is dynamic, but there is a list of tags stored in a Collection in the core data object. I want to be able to display this in a datagrid like so: Name tag1 tag2 tag3 Bob true true John true true I left out false, but that could be in ther...

Type.GetInterface and nested types

Hi, I just discovered a very strange behavior with Type.GetInterface and nested Types. The following sample code will show the problem, I am using the Type.FullName of an interface to check whether a given type derives from that interface: public interface IStandardInterface {} public class StandardClass : IStandardInterface {} class...

Java how to: Generic Array creation

Due to the implementation of Java Generics you can't have code like this. How can I implement this while maintaining type safety? public class GenSet<E> { private E a[]; public GenSet() { a = new E[INITIAL_ARRAY_LENGTH]; } } I saw a solution on the java forums that goes like this: import java.lang.refl...

Dynamically getting/setting a property of an object in C# 2005

I've inherited a code base and I'm writing a little tool to update a database for it. The code uses a data access layer like SubSonic (but it is home-grown). There are many properties of an object, like "id", "templateFROM" and "templateTO", but there are 50 of them. On screen, I can't display all 50 properties each in their own textb...

How to loop through all the properties of a class?

I have a class. Public Class Foo Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private _Age As String Public Property Age() As String Get Retur...

How to filter or find properties based on attributes

I have a class as follows Public Class Foo Private _Name As String <ShowInDisplay()> _ Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private _Age As String Public Property Age() As St...

How to copy value from class X to class Y with the same property name in c#?

Suppose I have two classes: public class Student { public int Id {get; set;} public string Name {get; set;} public IList<Course> Courses{ get; set;} } public class StudentDTO { public int Id {get; set;} public string Name {get; set;} public IList<CourseDTO> Courses{ get; set;} } I would like to copy value from...

VB reflection in for each loop

I'm attempting to use an unknown type in a for each loop as per the following code: private sub ReflectThis(ByVal rawData As Object()) Dim dataType As Type = rawData(0).GetType() Dim properties As PropertyInfo() = dataType.getProperties() For Each item As dataType In rawData ''//AAAA For Each property As System.Reflection.Prop...

Is using reflection considered unOOPish?

What are the risks of using reflection? Does it go against OOP in any way? I started using it lightly in a C# project and now I find it practical in many scenarios. Thank you. ...

How do I get all the base types in an assembly?

So if I have an instance of System.Reflection.Assembly and I have the following model: class Person {} class Student : Person {} class Freshman : Student {} class Employee : Person {} class PersonList : ArrayList {} class StudentList : PersonList {} How can I enumerate the assembly's types to get a reference to only the Person and...

How do I get all the bottom types in an assembly?

This is sister question to this one If I have an instance of System.Reflection.Assembly and I have the following model: class Person {} class Student : Person {} class Freshman : Student {} class Employee : Person {} class PersonList : ArrayList {} class StudentList : PersonList {} How can I enumerate the assembly's types to get a...

How can I locate a specific type in an Assembly *efficiently*?

I'm looking for a more efficient way to find a type in an Assembly that derives from a known specific type. Basically, I have a plugin architecture in my application, and for the longest time we've been doing this: For Each t As Type In assem.GetTypes() If t.BaseType Is pluginType Then 'Do Stuff here' End If Next Some ...

When enumerating a type's interfaces how do I get only those that are directly inherited?

I'm not sure of the exact terminology here. Basically, if I have a model like: class Student : IDoSchool {} class Freshman : Student {} interface IDoSchool {} What code would tell me that Freshman doesn't directly implement any interfaces and Student directly implements IDoSchool? In other words (disregarding bad terminology) I want ...

HOW TO: Get contained type in a Generic List through reflection?

Through reflection, is there some way for me to look at a generic List's contained type to see what type the collection is of? For example: I have a simple set of business objects that derive from an interface, like this: public interface IEntityBase{} public class BusinessEntity : IEntityBase { public IList<string> SomeString...

How to get interface basetype via reflection?

public interface IBar {} public interface IFoo : IBar {} typeof(IFoo).BaseType == null How can I get IBar? ...

Binding IList<IMyInterfaceType> doesn't display members of Interfaces that IMyInterface inherits

I'm binding IList to a GridView. IMyInterface looks like public interface IMyInterface: IHasTotalHours, IHasLines { DateTime GoalStartDate { get; set; } DateTime GoalEndDate { get; set; } } I bind an instance to a Grid like this: IList<IMyInterface> instance= GetMyData(); myGrid.DataSource = instance; myGrid.DataBind(); Wh...

When you say Ruby is reflective, does this mainly refer to "duck typing"?

I was reading a text describing Ruby and it said the following: Ruby is considered a “reflective” language because it’s possible for a Ruby program to analyze itself (in terms of its make-up), make adjustments to the way it works, and even overwrite its own code with other code. I'm confused by this term 'reflective' - ...

Is monkey patching/class-reopening really an example of reflection?

Apologies for the recursive nature of this question but the chosen answer to a question on SO got me questioning my understanding of reflection. I thought reflection was mainly about querying the internal happenings of a program while it's running. The example given in this response patches Ruby's built-in Integer class. Isn't this m...