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? ...
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? ...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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. ...
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...
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...
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 ...
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 ...
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...
public interface IBar {} public interface IFoo : IBar {} typeof(IFoo).BaseType == null How can I get IBar? ...
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...
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' - ...
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...