reflection

How can I build a 'dependency tree diagram' from my .NET solution

I can get easily see what projects and dlls a single project references from within a Visual Studio .NET project. Is there any application or use of reflection that can build me a full dependency tree that I can use to plot a graphical chart of dependencies? ...

How to tell if a Javascript function is defined

How do you tell if a function in Javascript is defined? I want to do something like function something_cool(text, callback){ alert(text); if( callback != null ){ callback(); }; } but that gets me a 'callback is not a function' error when callback is not defined. ...

Attribute & Reflection libraries for C++?

Most mature C++ projects seem to have an own reflection and attribute system, i.e for defining attributes which can be accessed by string and are automatically serializable. At least many C++ projects I participated in seemed to reinvent the wheel. Do you know any good open source libraries for C++ which support reflection and attribute...

What is the .NET equivalent of PHP var_dump?

I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString() on all of an object's properties and format it nicely for display. Yes, I know everything I could want will be accessible through the debugger, but I'm wondering if anyone knows that command? ...

How to programmatically determine param name when constructing an ArgumentException?

When constructing an ArgumentException, a couple of the overloads take a string that is the invalid argument's parameter name. I figure it would be nice to not have to remember to update this ctor param whenever I change the method's param name. Is there a simple way to do this using reflection? Update: thanks to the 2 respondents so fa...

Find a private field with Reflection?

Given this class class Foo { // Want to find _bar with reflection [SomeAttribute] private string _bar; public string BigBar { get { return this._bar; } } } I want to find the private item _bar that I will mark with a attribute. Is that possible? I have done this with properties where I have looked ...

Do access modifiers affect reflection also?

I always believe they did, but seeing some answers here make me doubt... Can I access private fields/properties/methods from outside a class through reflection? ...

What is the easier way to know if a type param implements an interface in c# 2.0?

For example, given a type param method i'm looking for something like the part in bold void MyMethod< T >() { if ( typeof(T).Implements( IMyInterface ) ) { //Do something else //Do something else } Anwers using C# 3.0 are also welcome, but first drop the .NET 2.0 ones please ;) ...

How do you get the root namespace of an assembly?

Given an instance of System.Reflection.Assembly. ...

Can I get calling instance from within method via reflection/diagnostics?

Is there any way via System.Reflection, System.Diagnostics or other to get a reference to the actual instance that is calling a static method without passing it in to the method itself. For example, something along these lines class A { public void DoSomething() { StaticClass.ExecuteMethod(); } } class B { public...

What is the difference between, IsAssignableFrom and GetInterface?

Using reflection in .Net, what is the differnce between: if (foo.IsAssignableFrom(IBar)) And if (foo.GetInterface(typeof(IBar).FullName) != null) Which is more appropriate, why? When could one or the other fail? ...

How would you get the Sql Command objects for a Given TableAdaptor and SqlDataAdaptor in C# (.NET 2.0)

I am creating a generic error handling / logging class for our applications. The goal is to log the exception info, info about the class and function (as well as parameters) and if relevant, the information about the System.Data.SqlClient.SqlCommand object. I would like to be able to handle passing in SqlCommands, TableAdaptors, and Sql...

What is Your Favourite Area of the Java API?

I'm curious to know what other Java programmers feel is their favorite part of the language, why they feel that way, and why other programmers should want an intimate knowledge of it as well. I'm looking for reasons like simplicity, performance, etc. Thanks. ...

Accessing a Collection Through Reflection

Is there a way to iterate (through foreach preferably) over a collection using reflection? I'm iterating over the properties in an object using reflection, and when the program gets to a type that is a collection, I'd like it to iterate over the contents of the collection and be able to access the objects in the collection. At the mome...

How do I find out what type each object is in a ArrayList<Object>?

I have a ArrayList made up of different elements imported from a db, made up of strings, numbers, doubles and ints. Is there a way to use a reflection type technique to find out what each type of data each element holds? FYI: The reason that there is so many types of data is that this is a piece of java code being written to be implem...

How do I determine the value of a generic parameter on my class instance

I have a marker interface defined as public interface IExtender<T> { } I have a class that implements IExtender public class UserExtender : IExtender<User> At runtime I recieve the UserExtender type as a parameter to my evaluating method public Type Evaluate(Type type) // type == typeof(UserExtender) How do I make my Evaluate me...

Create anonymous object by Reflection in C#

Is there any way to create C# 3.0 anonymous object via Reflection at runtime in .NET 3.5? I'd like to support them in my serialization scheme, so I need a way to manipulate them programmatically. edited later to clarify the use case An extra constraint is that I will be running all of it inside a Silverlight app, so extra runtimes are ...

memberInfo.GetValue() csharp

How to get an instance's member's values? With propertyInfos there is a propertyInfo.GetValue(instance, index), but no such thing exists in memberInfo. I searched the net, but it seems to stop at getting the member's name and type. ...

Determining the extended interfaces of a Class

I need to determine if a Class object representing an interface extends another interface, ie: package a.b.c.d; public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{ } according to the spec Class.getSuperClass() will return null for an Interface. If this Class represents either the Object class, an interf...

Assembly.GetCallingAssembly() and static constructors?

Ok, so I just ran into the following problem that raised an eyebrow. For various reasons I have a testing setup where Testing classes in a TestingAssembly.dll depend on the TestingBase class in a BaseTestingAssembly.dll. One of the things the TestBase does in the meantime is look for a certain embedded resource in its own and the callin...