I'm getting the Product attribute from all the loaded assemblies in my application using:
AssemblyProductAttribute product
= (AssemblyProductAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyProductAttribute));
I would like to get this attribute for all the assemblies that the currently loaded assemblies ref...
I am referencing a COM library in Visual Studio, so it has automatically created the corresponding Interop assembly for me. I would like to do a GetType() on these com objects, but they always return System.__ComObject. Querying them for an interface works though:
bool isOfType = someComeObject is ISomeComObject; //this works
But what...
I'm wondering if it's possible to use reflection to locate an object at runtime? This is more of an experiment than a practical requirement.
I've used the .GetType() method on an object instance to do various things to the object, but my question is: what if I know an object of a certain type exists at runtime, but I can't refer to it b...
Consider the following code:
public class A
{
}
public class B : A
{
}
public class C : B
{
}
class D
{
public static bool IsDescendantOf(this System.Type thisType, System.Type thatType)
{
/// ???
}
void Main()
{
A cValue = new C();
C.GetType().IsDescendantOf(cValue.GetT...
In .NET, using reflection how can I get class variables that are used in a method?
Ex:
class A
{
UltraClass B = new(..);
SupaClass C = new(..);
void M1()
{
B.xyz(); // it can be a method call
int a = C.a; // a variable access
}
}
Note:
GetClassVariablesInMethod(M1 MethodInfo) returns B and C varia...
Today, I discovered that using Collections.synchronizedXXX doesn't play well with reflection.
Here's a simple example:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Weird{
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("Hello Worl...
"abc".respond_to?(:sub) returns true, but String.respond_to?(:sub) returns false.
The second returns false, because it asks whether objects of the class Class have a method sub, as String is an Object of Class. It is the same for methods()…
How do I do these things and especialy respond_to?() without creating an Object of that class.
...
I know the class name, say "MyClass" and want to retrieve the Class object, ie. MyClass.class for future references. Is there a way to do that?
I've looked through the web but most of the things I found related to it were about the ClassLoader, which I presume are not suitable for my case. I do not want to initialize a class, but only g...
Context
I want to make this call via reflection
instanceOfEventPublisher.Publish<T>(T eventInst);
When I call
`
private void GenCall(IEventPublisher eventPublisher, object theEventObj){
var thePublisher = eventPublisher.GetType();
thePublisher.InvokeMember(
"Publish",
BindingFlags.Default | B...
I wanted to set a value of BrowsableAttribute for some of MyClass instance's properties at runtime:
public class MyClass
{
[Browsable(true)]
public int P1 { get; set }
...
}
Please advise how it can be done as well as how to add BrowsableAttribute to a MyClass instance's property at runtime if this attribute doesn't e...
This is for a job interview and I'd love it if someone could put an eyeball on this and say if I'm making any big mistakes. Here was the question:
1) Assume we're developing a JS-based
debugger, similar to Firebug, and we
need a way to inspect JS objects and
elements. Write a routing that takes
an object/element as input and...
class Employee(db.Model):
firstname = db.StringProperty()
lastname = db.StringProperty()
address1 = db.StringProperty()
timezone = db.FloatProperty() #might be -3.5 (can contain fractions)
class TestClassAttributes(webapp.RequestHandler):
"""
Enumerate attributes...
I am wanting to completely wrap an object so that all attribute and method requests get forwarded to the object it's wrapping, but also overriding any methods or variables that I want, as well as providing some of my own methods. This wrapper class should appear 100% as the existing class (isinstance must act as if it is actually the cla...
Hey guys. I have the following situation.
I want to use a TypeDescriptor to get the properties of a certain type. The type's depth in the inheritance hierarchy may vary. I only want to get the properties declared in the type itself and not in its parents (base). The problem is that when I call TypeDescriptor.GetProperties() it would ret...
I have a compex object
class A
{
int Field1;
int field2;
property ClassB ClassB;
property classC classC;
etc etc....
}
I want to print the complete object graph using reflection. Any good code out there?
...
i have such code
Bitmap b = new Bitmap(@"d:\0.bmp");
tessnet2.Tesseract ocr = new tessnet2.Tesseract();
ocr.DoOCR(b, Rectangle.Empty);
the i try to make it through reflection
Assembly a = Assembly.Load("tessnet2_32");
Type myType = a.GetType("tessnet2.Tesseract");
MethodInfo mymethod = myType.GetMethod("DoOCR");
Object obj = Activato...
Module M
Class C
end
end
What I need is something like:
M.was_defined_here?(M::C)
M.classes.include?(M::C)
Does this exists somehow?
I know I could parse M::C.name. But someebody could have the idea to change Module#name, to make it more astetic or something. I want a clean solution.
...
I'm wondering if there's any way to do the following:
function whatever($parameter)
{
echo funky_reflection_function();
}
whatever(5 == 7); // outputs "5 == 5" (not true or 1)
I'm not optimistic, but anyone know if theres any crazy hack I can do to do this?
...
How can I set a custom Host header in HttpWebRequest? I know that normally this class doesn't allow you to do so but is there anyway to use reflection or something like that without actually need me to send the whole packet with TCPClient?
...
Is it possible to override a private method by using Reflection in .NET 3.5?
...