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?
Closed as a duplicate of How do you loop through currently loaded assemblies?
...
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...
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....
Does creating an object using reflection rather than calling the class constructor result in any significant performance differences?
...
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!
...
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 ...
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....
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?
...
I know what Reflection is but why would I need to use it in a typical line-of-business Winforms app?
...
Is there a way to get the name of the currently executing method in Java?
...
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...
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...
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...
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...
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...
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?
...
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....
I need to get a list of assemblies in a Directory, Is there another way than this
System.IO.Directory.GetFiles(directory, "*.dll")
...
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)...