reflection

Reflection Related How much speed am i sacrificing?

private Equipment GenerateDirtyPropertiesOnEntity(Equipment updatedEntity) { updatedEntity.DirtyProperties.Clear(); Equipment originalEntity = GetEquipmentByGuid(updatedEnitity.Guid.Value); Type myType = updatedEntity.GetType(); System.Reflection.PropertyInfo[] properties = myType.GetProperties(); ...

Does Entity Framework/LINQ to SQL Data Binding use reflection?

Forgive me if this has been asked before; I did a search but couldn't find anything that specifically answered this question, but I'd be happy to be referred. I'm taking a peek at both the Entity Framework and LINQ to SQL, and while I like the systems (and of course the LINQ integration) I'm a little skeptical on the data-binding aspect...

Casting to a Type

I'm wondering if it's possible to cast an object to a Type... I've just started using Reflection, so maybe I'm doing it all wrong but here's what I would like to do: ... Type type = ...; Type interfaceType = someOtherType.GetInterface("IConverter`2"); return (Cast to interfaceType)Activator.CreateInstance(type); Is the cast to the in...

Test for Python module dependencies being installed

How could one test whether a set of modules is installed, given the names of the modules. E.g. modules = set(["sys", "os", "jinja"]) for module in modules: # if test(module exists): # do something While it's possible to write out the tests as: try: import sys except ImportError: print "No sys!" This is a bit cumbersome f...

Creating a typefrom Xml

Hi, i have a xml like this I want to parse the xml, build a dynamic class with spscified properties. i found some pointers to do it with system.reflection.emit namespace, but i do i always have to create an assembly and module in order to define the type? can i just create a type and define the properties? <Root> <type> <name>mytype<...

How can I use the SqlFunctionAttribute in a database project to generate the SQL to deploy the functions myself? Visual studio fails.

Background: Visual studio fails at deploying a database project. It tries to drop functions that are already referenced (e.g. in a check constraint), rather than just adding the new ones and updating the existing ones, so the deployment always fails. As a result, I'm writing my own code to update the assembly and add/update any functi...

Disable Java reflection for the current thread

I need to call some semi-trustworthy Java code and want to disable the ability to use reflection for the duration of that code's execution. try{ // disable reflection somehow someObject.method(); } finally{ // enable reflection again } Can this be done with a SecurityManager, and if so, how? Clarification/Context: This is ...

PHP equivalent of send and getattr?

If Ruby gets invited to a party and brings: foobarobject.send('foomethod') .. and Python gets invited to the same party and brings: getattr(foobarobject, 'foomethod')() .. what does PHP have to bring to the party? Bonus question: If Ruby and Python got jealous of PHP's party-favors, what English terms would they search for in PHP...

How slow is Reflection (C#)

I recently created an interface layer to distinguish the DataAccessProvider from our Business logic layer. With this approach we can change our choice of DataAccessProvider whenever we want by changing the values in the Web/App.Config. (more details can be given if needed). Anyway, to do this we use reflection to accomplish our DataProv...

Python reflection - Can I use this to get the source code of a method definition.

Duplicate of.. How can I get the code of python function? print the code which defined a lambda function Python: How do you get Python to write down the code of a function it has in memory? I have a method definition which is successfully running, but would like to modify it in runtime. for eg: If i have a method def sayHello(): ...

Reflection and casting

I have the following scenario, with exception being thrown when I try to cast: I added a project reference and imported the project's namespace. The LoadFile line loads the dll that is generated when this project is built. I am trying to access the public field of an attribute that decorates a property of an object from the dll. Here i...

Reflection and multi dimensional arrays

I have code that uses reflection on an input object and does some processing on the data stored in the object. The input object can be anything like String or int or double etc., sometimes it can be a multi dimensional array. I know how to do it for two dimensional arrays but I would prefer something that would work for any given dimensi...

ReflectionPermission Exception

I am currently working on an application using WPF and MVVM. Now if i go to another user's machine and try to launch my app, i get an Exception due to missing ReflectionPermission at BindToMethodInfo(Object, RuntimeMethodHandle, RuntimeTypeHandle, DelegateBindingFlags) in mscorlib. Now my question is, what exactly requires the Reflectio...

C#: Return a delegate given an object and a method name

Suppose I'm given an object and a string that holds a method name, how can I return a delegate to that method (of that method?) ? Example: MyDelegate GetByName(ISomeObject obj, string methodName) { ... return new MyDelegate(...); } ISomeObject someObject = ...; MyDelegate myDelegate = GetByName(someObject, "ToString"); //myDe...

How do you pass parameters by ref when calling a static method using reflection?

I'm calling a static method on an object using reflection: MyType.GetMethod("MyMethod", BindingFlags.Static).Invoke(null, new object[] { Parameter1, Parameter2 }); How do you pass parameters by ref, rather that by value? I assume they would be by value by default. The first parameter ("Parameter1" in the array) should be by ref, but...

C# - Reflection using Generics: Problem with Nested collections of ILists

Hi Everyone, I would like to be able to print object properties, and I've hit a snag when I hit nested collections of the iLists. foreach (PropertyInformation p in properties) { //Ensure IList type, then perform recursive call if (p.PropertyType.IsGenericType) { ...

Why can't I share types with an assembly loaded dynamically at runtime into the same load context?

I have a problem that is not uncommon when building a plug-in architecture. Assembly A is the core code -- the framework. Assembly B is a plugin to that code, expected to load dynamically at runtime and make code available for Assembly A to use. In Visual Studio, Project B (which generates Assembly B) has a reference to Project A (wh...

DynamicMethod with generic type parameters

Hi, Is it possible to define a DynamicMethod with generic type parameters? The MethodBuilder class has the DefineGenericParameters method. Does the DynamicMethod have a counterpart? For example is it possible to create method with a signature like the one given blow using DynamicMethod? void T Foo<T>(T a1, int a2) Thanks -- Best re...

How to obtain ASP.NET debugging path using reflection?

I'm trying to load an assembly and instantiate a type contained on it using reflection. The assembly is included in the references and is copied to the Bin folder after publishing, but when debugging, the assembly is not found. I noticed that each assembly is deployed to a different temp folder for debug, something like: C:\Users\Raf...

Accessing the list of Controllers/Actions in an ASP.NET MVC application

We know that behind the scenes, the ASP.NET MVC framework will use reflection to determine what controllers/actions are available to be executed, based on which classes derive from System.Web.Mvc.Controller and, of those classes, which methods return an ActionResult object. To my question - is it possible to access this list of control...