reflection

Reflection - Iterate object's properties recursively within my own assemblies (Vb.Net/3.5)

Hi, I wonder if anyone can help me - I've not done much with reflection but understand the basic principles. What I'm trying to do: I'm in the process of developing a class that gathers a lot of information about the local system, network, etc... to be used for automated bug reporting. Instead of having to change my test harness every...

C# Reflection Problem

I'm having the following problem when using reflection. The following statement evaluates to false: object[] attributes = someType.GetCustomAttributes(true); if (attributes[0] is NUnit.Framework.TestFixtureAttribute) return true; However this evaluates to true: object[] attributes = someType.GetCustomAttributes(true); if (attr...

How to get the type for a class by sending just the name of the class instead of the class itself as the parameter?

Dim a as Type=GetType(className) would gimme the type. But I have only the name of the class as string. I want something like GetType("class1") which would return the type. ...

How to declare a function during program execution?

This is something like Reflection where you can call a method simply by its name, and not a precompiled pointer to it. Like in JavaScript you can: var fun = function(){ alert("Hello World!"); } fun(); Is something like that possible in Java/J2ME? How? ...

Are Hecl scripts as powerful as native J2ME midlets?

Looking over Hecl, the scripting language with a J2ME runtime, I wonder about its capabilities: Assuming my base Midlet has methods and variables that I've written Can the Hecl interpreter run within my Midlet, and side-by-side with my classes? Can the Hecl script call any of my methods within the Midlet? Can the Hecl script utilize a...

howto get defined operators for a type in .net

I'm trying to get the list of defined operators for a specific type in order to see what kind of operations can be applied to that type. For example, the type Guid supports operations == and !=. So if user wants to apply <= operation for a Guid type i can handle this situation before an exception occurs. Or if i could have the list ...

C# add a reference using only code (no IDE "Add Reference" functions)

Hello, I am writting a plugin for a program, and I want to put my code inside a DLL so I can share the plugin freely without exposing (giving away) my code. Here is the basic structure i have access to : using System; public class Plugin { public void Initialize() { //do stuff here doWork(); } } Then i jus...

Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control?

I have a custom server control for asp.net. One of the properties available to it is a generic object. That generic object has custom attributes that are read and used to customize the rendering of the control. At run time, this is no problem, since all I need to do is find all the attributes on the instance that gets passed into the ...

C# Generics Question

I have a couple of areas in an application I am building where it looks like I may have to violate the living daylights out of the DRY (Don't Repeat Yourself) principle. I'd really like to stay dry and not get hosed and wondered if someone might be able to offer me a poncho. For background, I am using C#/.NET 3.51 SP1, Sql Server 2008, a...

Getting underlying type of a proxy object

I'm using Castle DynamicProxy and my ViewModels are a proxy, something like this: namespace MyApplication.ViewModels { public class MyViewModel : BaseViewModel, IMyViewModel { } } a proxy of my viewmodel looks like this though: {Name = "IRootViewModelProxyffecb133f590422098ca7c0ac13b8f98" FullName = "IRootViewModelProxyffec...

C# Reflection Utility

I have written the following Utility class to get an instance of any class of name "className". public class AssemblyUtils { private AssemblyUtils() { } public static T GetInstance<T>(string assemblyName, string className) { T classInstance = default(T); System.Reflec...

Getting the attributes of a field using reflection in C#

I wrote a method that extracts fields from an object like this: private static string GetHTMLStatic(ref Object objectX, ref List<string> ExludeFields) { Type objectType = objectX.GetType(); FieldInfo[] fieldInfo = objectType.GetFields(); foreach (FieldInfo field in fieldInfo) { if(!ExludeFields.Contains(field.Na...

Calling a method on a static class given it's type name and method names as strings.

How could I go about calling a method on a static class given the class name and the method name, please? For example: Given "System.Environment" and "GetFolderPath", I'd like to use reflection to call Environment.GetFolderPath(). Thanks, Dan ...

Instantiating a class using Reflection

Suppose I have three projects in my sln. (1) xyz.a{Class Lib}{no reference added} (2) yzx.b{Class Lib}{added the reference of xyz.a} (3) zxy.c{Console App}{added the reference of xyz.a} Now, I need to create the instance of a class residing in yzx.b from within xyz.a using reflection. And also this should be independent of the folder...

Dynamically get the result of a Func<T,bool> invocation

Hi, I am trying to serialize something based upon meeting particular criteria. To this end my original hope was to use attributes containing a lambda expression on an object's properties. However, as this cannot be done I've settled for having a Func<T,bool> member within the class and passing the type (or first parameter type) and na...

getting the name of the calling method

Basically i've got a web service that i'm trying to put some kind of usage logging in. To do this i've created a class with a logging method. I instatiate the class on the service and then call the logging method in each of the web methods. I'm trying to find a way of getting the name of the method that has called the loggong method Pu...

Why are constructors returned by ReflectionFactor.newConstructorForSerialization() called "munged"?

In Java, one can create instances of a class without actually calling a declared constructor by retrieving one via sun.reflect.ReflectionFactor.newConstructorForSerialization(). As far as I know, this special constructor is called "munged". Where does this term come from? I could not find it in any dictionary. ...

Determine all referenced assemblies

I need to determine all assemblies referenced by a certain .NET Compact Framework assembly. Do you think this is possible with Cecil? This way our deployment tools could automatically resolve all dependencies of our .NET Compact Framework applications. ...

propertybinding with reflectiontypes

In my project i'm creating new Typeobject (using Reflection) So i have object of type {TempType41459726} (for example) How can i add DataBinding to the properties of these object? Binding binding = new Binding("propertyname"); binding.Source = this.Action; binding.Mode = BindingMode.TwoWay; element.SetBinding(e...

C#: Getting value via reflection

Hi, i would like to know if it's possible to do something like this: class brand { string name; } class car { string carname; brand carbrand; } now i've got a string like this and an instantiated object of the type car: car carobject = new car(); string brandNameOfCar = DoSomeMagicalReflectionStuff(car, "car.brand.name")...