How to enumerate an object's properties in Python?
I C# we do it through reflection. In Javascript it is simple as: for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; How to do it in Python? ...
I C# we do it through reflection. In Javascript it is simple as: for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; How to do it in Python? ...
Is there any mini C# console application available to pursue Reflection ? ...
For example: Class A { M1() { B.M2(); } } class B { public static M2() { // I need some code here to find out the name of the method that called this method, preferably the name of the declared type of the calling method also. } } ...
I need to pass a generic type parameter to an interface. I have a string with the name of the type. I have something like this: string type = "ClassType"; Type t = Type.GetType("ClassType"); IProvider<t> provider = (IProvider<t>)someObject; This doesn't work for me. What is the correct way to do it? Thanks. ...
I've been given no other choice but to access a set of classes, which I cannot modify, with this structure through reflection. Using the method shown in the main method below however, throws a NullPointerException. The null pointer being "table" in the constructor when f1.get(null) is called. I am unable to instantiate the classes befo...
If I do a Assembly.ReflectionOnlyLoadFrom(), is it possible to unload the assembly? Or, can it be unloaded only if it is in a separate AppDomain, as with Assembly.LoadFrom() ? I have a tool that needs to load an assembly for inspection. ...
I want to replace calls to a given class with calls to anther class within a method body whilst parsing compiled class files... or put another way, is there a method of detecting usages of a given class in a method and replacing just that part of the method using something like javaassist. for example.. if I had the compiled version of...
Hello there, How can I access an internal class of an assembly? Say I want to access System.ComponentModel.Design.DesignerHost. Here the DesignerHost is an internal and sealed class. How can I write a code to load the assembly and the type. Thanks, Dattebayo... ...
I have a handful of helper methods that convert enum values into a list of strings suitable for display by an HTML <select> element. I was wondering if it's possible to refactor these into a single polymorphic method. This is an example of one of my existing methods: /** * Gets the list of available colours. * * @return the list o...
I have code like: var t = SomeInstanceOfSomeClass.GetType(); ((t)SomeOtherObjectIWantToCast).someMethodInSomeClass(...); That won't do, the compiler returns an error about the (t) saying Type or namespace expected. How can you do this? I'm sure it's actually really obvious.... ...
Ok I have a generic interface public IConfigurationValidator<T> { void Validate(); } a class that implements it: public class SMTPServerValidator : IConfigurationValidator<string> { public void Validate(string value) { if (string.IsNullOrEmpty(value)) { throw new Exceptio...
I want to use reflection to set some fields according to data from a file. The information that I can have is TypeName, TypeValue and FieldName. While this is trivial on classes (Activator.CreateInstance and PropertyInfo.SetValue), I am a bit dumbstruck when it comes to value types like Int32 which does not have any properties. I see th...
Are there any disadvantages in performance by using the CallByName function in VB.NET? Is there any better way to do the call by Name in .NET 2.0 onwards. ...
Assuming I have a class like public class FooImpl { public void bar(){}; } Is there a way to create its interface at runtime? e.g. public interface Foo { public void bar(); } I have been looking into Javasssist and the truth is it's reflection that I'm interested in using the interface for (as Esko Luontola and Yishai stat...
How do you get a collection of all the types that inherit from a specific other type? ...
I would like to assertain the class name of an aspx page from within a user control. How can I go about doing this? ...
Hi, I am trying to use reflection to collect a property from a class that returns a certain type. However some of the properties I'm returning are strongly typed lists that house the type I want. Essentially I am trying to do the following: Public Function GetPropertyInfo(ByVal t as System.Type) for each pi as System.Reflection.Prop...
I know this is not exactly reflection, but kind of. I want to make a debug function that gets a variable and prints a var_dump and the variable name. Of course, when the programmer writes a call to the function, they already know the variable's name, so they could write something like: debug( $myvar, 'myvar' ); But I want it to be qui...
Let's say I have the following code which update a field of a struct using reflection. Since the struct instance is copied into the DynamicUpdate method, it needs to be boxed to an object before being passed. struct Person { public int id; } class Test { static void Main() { object person = RuntimeHelpers.GetObject...
Hi, I have a problem, I wish to use reflection to generate instances of one of a set of classes at runtime. However, I have hit a snag. I want to get all of the classes involved to register themselves so the appropriate class can be chosen from a GUI. I can do this using a static code block in each file which provides a tidy OO solution...