reflection

How to copy a subset of a list using generics and reflection

I need to copy a sub set of items from one list to another. However I do not know what kind of items are in the list - or even if the object being passed is a list. I can see if the object is a list by the following code t = DataSource.GetType(); if (t.IsGenericType) { Type elementType = t.GetGenericArguments()[0]; } What I cann...

Why can not use reflection in f#

Reflector currently added F# but its not work fine, is it possible to use reflection for F#, if not why? I read this. It was for 2008, but if you check some code like bellow in ildasm you can't see anything about Units of Measure. // Learn more about F# at http://fsharp.net [<Measure>] type m [<Measure>] type cm let CalculateVelocity...

C# Run From Bytes

I am working on making my client open another program by downloading the bytes and using reflection to open it. I have currently got this working on a C# Console Application, but when I try and do it on a Windows Form Application I get this error. "Exception has been thrown by the target of an invocation." Here is the code using Syste...

How to get type parameters from SYBs dataTypeOf

Given a data type data Foo = Foo1 { foo1Name :: String} | Foo2 { foo2Name :: String, foo2Age :: Integer } I would like to be able to extract the Data.Data.DataTypeS of Foo1 and Foo2s fields. I tried datatype = (undefined :: Foo) constrs = dataTypeConstrs datatype foo1 = fromConstrs (head constrs) :: Foo foo1Fields = gmapQ dataT...

Create an anonymous type from reflection ParamInfo[]

i want to create an anonymous type inside a function, when the anonymous type properties are the function parameters. for example, for the function: private bool CreatePerson(string FirstName, string LasName, int Age, int height); i will have an anonymous type with the properties: FirstName,LasName,Age and height. and the values of the...

C# - Get namespace function belongs to?

Something alike, if I input the string "Console.WriteLine", it would return -> "System.Console.WriteLine" I assume there's some way via Reflection. ...

Type.GetType fails to create type from already loaded assembly

I have program which loads an assembly using Asssembly.LoadFrom method. Some time later I attempt to use Type.GetType to create a type from that assembly (using AssemblyQualifiedName), but the method returns null. If I set it to throw exception, it tells Could not load file or assembly '...' or one of its dependencies. The system ...

Case-insensitive GetMethod?

foreach(var filter in filters) { var filterType = typeof(Filters); var method = filterType.GetMethod(filter); if (method != null) value = (string)method.Invoke(null, new[] { value }); } Is there a case-insensitive way to get a method? ...

Java: what about my classOf and newArray ?

Here, I wondered about how to implement Collection#toArray(T[] array) properly. I was mostly annoyed that array.getClass().getComponentType() is of type Class<?> and not Class<? extends T> as I would have expected. Therefore, I coded these three functions: @SuppressWarnings("unchecked") static <T> Class<? extends T> classOf(T obj) { ...

Iterate recursively on properties of an object

I want to get all properties of an object during runtime and save it on a batabase together with its values. I am doing this recursively i.e. whenever a property is also on object, I will call the same method and pass the property as a parameter. See my code below: private void SaveProperties(object entity) { PropertyInfo[] proper...

Enum.valueOf(Class<T> enumType, String name) question

I am trying to get around a compile error ("Bound mismatch: ...") relating to dynamic enum lookup. Basically I want to achieve something like this: String enumName = whatever.getEnumName(); Class<? extends Enum<?>> enumClass = whatever.getEnumClass(); Enum<?> enumValue = Enum.valueOf(enumClass, enumName); Whatever I do, I always end ...

Reflection: optimize performance

Hello, i want to know if i could optimize the reflection part of my app. Background information: the vb.net windows application checks if database records apply on different rules. So i created an Interface iRule and (so far) 54 rules-classes that are implementing it. They all belong to the same project(Rule.dll). Because people shou...

Generic Object to '|'-separated string serialization

I have written this class-methods for .net 2.0 to create objects from '|'-separated strings and vise-versa. But the problem is, they are not giving right results in case of Inherted types, i.e. inherited properties are coming last and the sequence of the data supplied in the form of a '|'-separated string is not working. For example: ...

Why predicate isn't filtering when building it via reflection

I'm building a rather large filter based on an SearchObject that has 50+ fields that can be searched. Rather than building my where clause for each one of these individually I thought I'd use some slight of hand and try building custom attribute suppling the necessary information and then using reflection to build out each of my predica...

Reflection class to get all properties of any object

Hello, I need to make a function that get all the properies of an object (including an children objects) This is for my error logging feature. Right now my code always returns 0 properties. Please let me know what I'm doing wrong, thanks! public static string GetAllProperiesOfObject(object thisObject) { string result = string.Empty;...

Is there a tool to generate a sample application configuration by analyzing a ConfigurationSection type and its attributes?

I am working on an application that has a large set of configuration values, modelled and organized through the .NET configuration types from the System.Configuration namespace (i.e. ConfigurationSection, ConfigurationProperty, ConfigurationElement, etc...). Several values are required and may or may not have defaults, while others are ...

.NET Reflective Dependency Injection with Multiple Containers

Hi Guys, I'm relatively new to dependency injection, so I'm probably butchering the concept to some extent. However, I'm trying to achieve something like the following, but am unsure as to whether or not it's feasible: Lets say I have two containers, each containing different instances of the same type of dependency. For example, each ...

PropertyDescriptor GetChildProperties doesn't return properties from type extending interface which inherited another interface

the 3rd assert in this test fails but if I would move the Id property from IEntity to IFoo it will work I need to get all the properties, how to do this ? (whitout passing an instance, for some reason this way works) [TestFixture] public class DescriptorTests { [Test] public void Test() { va...

Get callers method (not name)

I would like to get the calling method java.lang.reflect.Method. NOT the name of the method. Here is an example how to get the callers Class. // find the callers class Thread t = Thread.getCurrentThread(); Class<?> klass = Class.forName(t.getStackTrace()[2].getClassName()); // do something with the class (like processing its annotation...

Is there a way to get behavior similar to default(T) using reflection?

I'm refactoring some code that was originally designed with generics to also work with reflection. The particular code base has default(T) scattered throughout. I've created a method that will look similar named Default(T), but I don't think my implementation is correct. Essentially my implementation looks like this: private object D...