reflection

c# - How to check if property setter is public

Given a PropertyInfo object, how can I check that the setter of the property is public? ...

Get all base property declarations within a class hierarchy

Consider this interesting set of types: class A { public virtual int MyProperty { get; set; } } class B : A { public override int MyProperty { get; set; } } class C : B { public new virtual int MyProperty { get; set; } } class D : C { public override int MyProperty { get; set; } } class E : D { public new int MyPro...

Is there a way to determine if a generic type is built from a specific generic type definition?

I've got a generic method: Func<IEnumerable<T>, bool> CreateFunction<T>() where T can be any number of different types. This method does a bunch of stuff using reflection and if T is an IDictionary, regardless of the the dictionary's TKey and TValue I need to execute dictionary specific code. So the method could be called: var f = C...

Why would this code complain about "the arity of the generic type definition"?

I've got a generic type: class DictionaryComparer<TKey, TValue> : IEqualityComparer<IDictionary<TKey, TValue>> And a factory method that will (should) create an instance of this class for a given dictionary type. private static IEqualityComparer<T> CreateDictionaryComparer<T>() { Type def = typeof(DictionaryComparer<,...

Getting non-public properties of a type via reflection c#

Is it possible to do it? How? Thank you for your help! ...

reflection is possible on obfuscation

I am struggling with this problem since last one week. I have obfuscated exe of my application. Our application is offline tool for online web application. Client will install this application and connect once to internet, application will download relevant information and store in xml file on client machine for further display. for secu...

How can I clean up this code?

I want to make my code look cleaner and 'express its intent' more.. The following method is reflecting over two types and checking that if there is a property in one type, then there is a corresponding property of the same name in the other type. If there is then it sets the value of the property to the index variable. otherwise it thro...

trouble invoking static method using reflection and c#

hi all. i have this two classes: Item<T> : BusinessBase<T> where T : Item<T> { public static T NewItem() { //some code here } } Video : Item <Video> { } now i want to invoke NewItem() method on class Video using reflection. when i try with this: MethodInfo inf = typeof(Video).GetMethod("NewItem", BindingFlags.St...

How to dynamically subscribe to an event?

RELATED Watch control to determine events being fired? I need to detect when an event is fired. To do so I am trying to subscribe dynamically on the event. The problem is that I have different types of delegates, not all events have the same signature. The solutions provided in here and here expects object sender, EventArgs e, whi...

Insert with Linq-to-SQL an object determined through reflection

I am trying to populate a row in a table given a key value list Using DataContext.Mapping I am able to locate the correct table (given a table name) and create a row. // Look up the table MetaTable matchedTable = null; foreach (MetaTable tableMetaData in db.Mapping.GetTables()) { if (table.Equals(t...

More efficient way to find if a class inherits an interface?

In C#, currently i'm doing the following code to filter out a specific set of classes that inherit from the CaptureType that is passed to the method. public static CaptureType[] ListPluginsWith<CaptureType>() { List<CaptureType> plugins = new List<CaptureType>(); foreach (var plugin in Bot.AutoPlugins) { ...

C# Reflection How-to?

I'm having trouble grasping reflection in C#, so I'm going to put my specific situation down and see what you guys can come up with. I've read TONS of C# reflection questions on here, but I still just simply don't get it. So here's my situation; I'm trying to access an array which is a non-public member of a class I have access to. ...

APIs for compare assemblies .NET (Reflection, MSIL) programmatically

For example I have Assembly1.dll (1.0.0.0) and Assembly1.dll (1.0.0.0), in differents folders and I want to compare differences (if each assembly has the same Classes and each class the same methods, or compare all MSIL code). any APIs for do this? There are tools, like this http://stackoverflow.com/questions/652432/compare-compiled-net...

Is there a better way to sort my IList-bound GridView?

I have an asp.net web application that has a page with a GridView. The GridView is bound to an IList object. As you may know, the .net framework does not provide for sorting of such a GridView; the sorting must be handled in code. Here's the code I was able to draft. As you can see, the issue is that the name of the field to sort by ...

How can I retrieve all methods of an event?

I have an event Load public delegate void OnLoad(int i); public event OnLoad Load; I subscribe to it with a method: public void Go() { Load += (x) => { }; } Is it possible to retrieve this method using reflection? How? ...

Groovy - reflection on a Java class - methods and parameters

How would you go about this reflection task in Groovy: (1) provide a class type to the Groovy function (2) loop over all the methods of this class (a) print out each parameter name and type from the method (b) print out the return type ...

How to get a delegate object from an EventInfo?

I need to get all events from the current class, and find out the methods that subscribe to it. Here I got some answers on how to do that, but I don't know how I can get the delegate when all I have is the EventInfo. var events = GetType().GetEvents(); foreach (var e in events) { Delegate d = e./*GetDelegateFromThisEventInfo()*/; ...

IEnumerable.GetProperties()

I have class Foo, which derived from interface IFoo and IEnumerable public class Foo:IFoo,IEnumerable { public decimal Count {...} ///etc... } How to call GetProperties(), that it's return only public properties of IEnumerable (not IFoo or this class)? ...

How can I change a method assigned on an event?

I am getting all events, with a certain attribute, and I want to modify these events adding a call to another method. var type = GetType(); var events = type.GetEvents().Where(e => e.GetCustomAttributes(typeof(ExecuteAttribute), false).Length > 0); foreach (var e in events) { var fi = type.GetField(e.Name, BindingFlags.NonPublic | ...

Is there a straightforward way to copy a Type using reflection?

I realize this is a very strange question. Let me just say that I have my reasons. (I tend to write very long, wordy questions; I want to keep this one short.) If I have some type T, can I use reflection to define a new type, let's call it T2, that will basically be identical to T? What I'm looking for is essentially a dynamic way to do...