reflection

C# Reflection: Getting the fields of a DataRow from a Typed DataSet

I am currently building a method that takes an object that is of type DataRow from a typed DataSet, and then returning a string in JSON format of the fields in the DataRow (for use in a Web Service). By using System.Reflection, I am doing something like this : public string getJson(DataRow r) { Type controlType = r.GetType...

How do I get a list of all currently loaded assemblies?

How do I get a list of all currently loaded assemblies? Closed as a duplicate of How do you loop through currently loaded assemblies? ...

Is there a good way of getting MethodInfo of open generic method?

Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1 parm); int Method2(int parm); } How do I get a methodInfo for its methods? for a regular non-generic method, like method2, I can go with typeof(IHaveGenericMethod).GetMethod("methodName",new Type[]{typeof(itsParamete...

Using generics and methodinfo

I am building a basic profiler for an open source project. One requirement is to measure execution time of a method. While this is easy enough, I have to do it without knowing the method or its containing class until runtime. The way to invoke the profiler will be when the user will invoke the profiler from the IDE in an active document....

Java Reflection Performance

Does creating an object using reflection rather than calling the class constructor result in any significant performance differences? ...

How to get all subclasses?

Hello, this is a common problem that I always have when I use different languages, for example in Smalltalk you can do something like: aClass allSubclasses What about other languages? Like Java? PHP? Python? Please post snippets! ...

How do I invoke a method through reflection with a lambda expression as a parameter?

I want to do this: MethodInfo m = myList.GetType().GetMethod("ConvertAll", System.Reflection.BindingFlags.InvokeMethod).MakeGenericMethod(typeof(object)); List<object> myConvertedList = (List<object>)m.Invoke(myList, new object[]{ (t => (object)t)}); myList is a generic list of a specific type (unknown to the application), and I want ...

Activator.CreateInstance with private sealed class

I'm trying to new up a LocalCommand instance which is a private class of System.Data.SqlClient.SqlCommandSet. I seem to be able to grab the type information just fine: Assembly sysData = Assembly.Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); localCmdType = sysData.GetType("System.Data.SqlClient....

Reflection runtime performance - Java vs CLR

A related post here pretty much established reflection in Java as a performance hog. Does that apply to the CLR as well? (C#, VB.NET, etc). EDIT: How does the CLR compare to Java when it comes to reflection? Was that ever benchmarked? ...

Why would I use Reflection in a business app?

I know what Reflection is but why would I need to use it in a typical line-of-business Winforms app? ...

Getting the name of the current executing method java

Is there a way to get the name of the currently executing method in Java? ...

MethodInfo for EntityCollection instead of Queryable

I am manually creating the equivalent lambda: var function = p => p.Child.Any(c => c.Field == "value"); I have a MethodInfo reference to the "Any" method used with Expressions built in code. MethodInfo method = typeof(Queryable).GetMethods() .Where(m => m.Name == "Any" && m.GetParameters().Length == 2) .Single().MakeG...

How to create a method that takes any object and returns a name:value pair for all properties ?

For example I have a simple class like public class Person{ public int Age {get;set;} public string Name {get;set;} } I need to make a method that takes any class and spits out values of properties set in the object as a string in format "Age:35;Name:John Doe;" I am looking for a method signature on the lines of public str...

Java toString() using reflection?

I was writing a toString() for a class in Java the other day by manually writing out each element of the class to a String and it occurred to me that using reflection it might be possible to create a generic toString() method that could work on ALL classes. I.E. it would figure out the field names and values and send them out to a String...

Strange parameter sequence using Reflection.Emit

I have been looking at Reflection.Emit recently. I wrote a simple program that generates a DynamicMethod which simple calls another method with the same parameters class Program { static void Main(string[] args) { Program p = new Program(); p.Test(); } public delegate void TestHandler(int a, int b, int c...

how to set nullable type via reflection code ( c#) ?

Need to set properties of a class via reflection. I have a dictionary with property names and string values. Inside a reflection loop - I need to convert the string value to appropriate property type while setting the value for each property. Some of these property types are nullable types. How to konw from PropertyInfo if the prop i...

What is the best way to get a property and value with a particular attribute?

Given this definition: [UniqueId("Ident")] public class MyClass : MyBase { public int Ident{ get; } } What is the best way from the "MyBase" class to get the "UniqueId" attribute, find the matching property name and get the underlying value? ...

ASP.NET MVC Authorization based on role membership or data relation (ownership)

I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at http://stackoverflow.com/questions/390930/asp-net-mvc-authorization-using-roles....

How to Get a List of Assemblies in csharp?

I need to get a list of assemblies in a Directory, Is there another way than this System.IO.Directory.GetFiles(directory, "*.dll") ...

How to get a Static property with Reflection

So this seems pretty basic but I can't get it to work. I have an Object, and I am using reflection to get to it's public properties. One of these properties is static and I'm having no luck getting to it. Public Function GetProp(ByRef obj As Object, ByVal propName as String) as PropertyInfo Return obj.GetType.GetProperty(propName)...