reflection

Cannot access Object fields using fieldinfo

Hi, I have an method that takes in an observable collection (returned from a webservice) of objects and analyzes them according to their attributes. Here is the code snippet from the method private double analyze(ObservableCollection mobjColl) { FieldInfo fi = null; foreach (MyApp.MyObj oi in mobjColl) ...

Check for implementation of an Interface recursively, c#

I have a situation in a WebForm where I need to recurse throguh the control tree to find all controls that implement a given interface. How would I do this? I have tried writing an extension method like this public static class ControlExtensions { public static List<T> FindControlsByInterface<T>(this Control control) { ...

What risk does Reflection pose? (Medium Trust)

The lack of reflection in Medium Trust hosting environments seems to cause a lot of problems for many popular web applications. Why is ReflectionPermission disabled by default with Medium Trust? What risk does reflection pose in a shared hosting environment? For random reference, see MSDN: How to use Medium Trust in ASP.NET 2.0 ...

C# Winforms PropertyGrid and ErrorProvider

I'm working on extending the errorprovider to the propertygrid and treeview controls. I found a very helpful post at: Example detailing how to add the errorprovider to a propertygrid, and it works very well. My question is how did the author know that IPropertyValueUIService is the interface that the propertygrid uses to display the i...

Using Reflection with COM Interop

After an interop call, I get back a COM object. I know this object will be one of three possible COM classes (Class1, Class2, Class3), but do not know which one in runtime. The reflection upon that object (interopObject.GetType()) returns the base RCW wrapper of System.__ComObject. What I need is to set some properties on the object - ...

Why does reflection not perform well in .NET?

I am interested to know the technical reasons: why does reflection not perform well in .NET? ...

Instantiate an instance from a specified assembly that inherits from a base class - apparently very difficult problem

I have a class: public abstract class SendAgencyFileComponent : ISendAgencyFileComponent { public AgencyOutput agencyOutput; public TDXDataTypes.DB.Entity client; public TDXDataTypes.DB.Entity agency; public SendAgencyFileComponent(AgencyOutput agencyOutput, TDXDataTypes.DB.Entity client, TDXDataTypes.DB.Entity agency) ...

Why does my .NET Attribute not perform an action?

Hi, I've created a simple Attribute: [AttributeUsage(AttributeTargets.Method)] public class InitAttribute : System.Attribute { public InitAttribute() { Console.WriteLine("Works!"); } } and I apply it to a simple method: static class Logger { public static string _severity; public static void Init(string s...

Postsharp: how does it work?

Following the advice got on another question of mine, I converted the code there quoted to be used with PostSharp: Attribute: [Serializable] public sealed class InitAttribute : OnMethodBoundaryAspect { public override void OnEntry(MethodExecutionEventArgs eventArgs) { Console.Write("Works!"); } } static class Logg...

C# Library for easy dynamic reflection

Hi, Is there any library (like open source projects etc) that makes it easier to use complex reflection like creating objects or classes on the fly, inspecting instances etc? Thanks ...

questions on annotation + class member order

I would like to do something like this: public class Foobar { @Tag final private int foo; @Tag final private int bar; @Tag final private int baz; @Tag final private int quux; static private final TagValidator validator = TagValidator.autoGenerate(Foobar.class); public Foobar(Something something) { va...

How can I use reflection in C# to find all the members of a class that meet the requirements of a specific delegate?

Hi, I've got a class that's got a bunch of public methods, and I'd like to reflect over it to find the set of member methods that could be used as a particular delegate. For example: delegate void InterestingFunc(int i); class Entity { public void F(); public void G(); public void H(int i); public void X(int i); } C...

Using reflection for code gen?

I'm writing a console tool to generate some C# code for objects in a class library. The best/easiest way I can actual generate the code is to use reflection after the library has been built. It works great, but this seems like a haphazard approch at best. Since the generated code will be compiled with the library, after making a change I...

Can a .NET object actually have no constructors, according to reflection?

I'm writing a really simple IoC/DI container, and I've got the following code: ConstructorInfo[] ctors = concreteType.GetConstructors(); if (ctors.Length == 0) return Activator.CreateInstance(concreteType); // more code goes here... I can't come up with a test case that results in a type having zero constructors, even with this:...

Create objective-c class instance by name?

Duplicate: http://stackoverflow.com/questions/1034350/dynamic-class-creation-in-objective-c/1034368#1034368 Is it possible to create an instance of a class by name? Something like: NSString* className = @"Car"; id* p = [Magic createClassByName:className]; [p turnOnEngine]; I don't know if this is possible in objective-c but seems lik...

Widening equality check for Method type

Suppose I have an interface: public interface FooInterface { public void someMethod(); } and I have a class that implements this interface: public class FooClass implements FooInterface { public void someMethod() { //do cool things } public void someOtherMethod() { //do other cool things } ...

unit test dynamic loading code

I was reading and found this code as an aswer to a question public List<T> LoadPlugin<T>(string directory) { Type interfaceType = typeof(T); List<T> implementations = new List<T>(); //TODO: perform checks to ensure type is valid foreach (var file in System.IO.Directory.GetFiles(directory)) { //TODO: add pro...

How do I get a selector from its name?

I have an NSString containing the name of a selector I would like to call with performSelector. How can I get a reference to the selector from the string? ...

Determine if a type is static

Let's say I have a Type called type. I want to determine if I can do this with my type (without actually doing this to each type): If type is System.Windows.Point then I could do this: Point point1 = new Point(); However if type is System.Environment then this will not fly: Environment environment1 = new Environment(); //wrong So...

Generic DuplicateValidationRule (Checking Business Objects for duplicates)

I'm trying to get this Generic DuplicateValidationRule working, which basically checks a Collection for duplicates (based on a generic business object type passed in). Lets take the IBankAccount Business Object for example: public interface IBankAccount : IMyBusinessObjectBase { IBank Bank { get; set; } IBankAccountType BankAcc...