I need to print arbitrary SimpleXML objects in a specific manner, with special handling of attribute nodes.
The problem is that SimpleXML elements and attributes seem to use exactly the same class, attribute node even pretends to support attributes() method, and SimpleXML hides its internals, so there doesn't seem to be any way to tell ...
How would one use .net reflection to determine the type of the executing assembly, by type I mean dll or exe. Currently its possible to do something like:
Assembly.GetExecutingAssembly().CodeBase.ToLower.EndsWith(".exe")
But it seems like something better could exist that does not need to do a string comparison, i.e. comparing the asse...
I have a C# application the performs some runtime compilation of source files containing calculations into dynamic assemblies. Obviously this presents a serious security issue.
From the following 'formula', the code below would be generated, and a dynamic assembly created:
Formula:
Int32 _index = value.LastIndexOf('.');
String _retVal...
So lets say I have an object that it stored in a Database:
com.test.dummy.Cat
The cat has an integer id.
Outside of my "world" the reference to the object is a String of the form:
Cat-433
Where 433 is the Cats assigned Database ID.
When I get the String passed to me, I need to be able to find it in the Database.
So I do this:
St...
In a DTO object I'd like to hard code the label description for the rendered html text box so that I can have an html helper function like TextBoxWithLabel where I pass only the object and it automatically creates the label taken from the description attributes.
public class MessageDTO
{
public int id { get; set; }
[Descriptio...
I have a class in C# with a public member. For example:
public class Foo
{
public int Bar;
}
I'd like to get the FieldInfo for Bar, without having to do:
return this.GetType().GetField("Bar");
I'm just looking for a cleaner, shorter way to do this. Something like:
return field(Bar);
I could, of course, build a method:
publi...
Say I want to loop through a datareader and create a load of objects of a certain type but using a value from the datareader as the object name e.g.
String "string_" + <value from datareader> = new String();
So if I had values temp1,temp2 & temp3 coming out of the datareader I would have 3 new objects of type string e.g.
string_temp1...
How can I access an inherited protected field from an object by reflection?
...
How do I get a list of all the properties of a class?
...
Hi. I'm trying to validate that a parameter is both an out parameter and extends an interface (ICollection). The reflection api doesn't seem to want to give me the "real" type of the parameter, only the one with an "&" at the end which will not evaluate correctly in an IsAssignableFrom statement. I've written some c# code that works but ...
I'm playing around with Reflection and I thought I'd make something which loads a class and prints the names of all fields in the class.
I've made a small hello world type of class to have something to inspect:
kent@rat:~/eclipsews/SmallExample/bin$ ls
IndependentClass.class
kent@rat:~/eclipsews/SmallExample/bin$ java IndependentClass
...
Can anyone tell me how I would create a MustOverride property using Reflection?
...
I want to write a program to find all the com visible .NET classes, and their ProgIDs from a .NET assembly. What's the best way to do this?
...
Hello,
I have assembly A that depends (statically) on type T (reference type, a class) in assembly B.
I do not own assembly A but I do own assembly B. T unfortunately is a real type (not an interface) but luckily A uses reflection to discover its members.
I want to be able to create dynamically B (and T). The only important item is th...
Java's java.lang.Class class has a getDeclaredFields method which will return all the fields in a given class. Is there something similar for Common Lisp? I came across some helpful functions such as describe, inspect and symbol-plist after reading trying out the instructions in Successful Lisp, Chapter 10 (http://www.psg.com/~dlamkins/s...
I'm trying to put together a plugins system with .NET, and I'm not sure if I'm doing it correctly. The basis of the system is that a specific directory ({apppath}/Plugins/) will have a bunch of precompiled DLLs, and I want to look through each one with reflection, and for every class available, if it inherits a specific base class (this...
How would you, in C#, determine the name of the variable that was used in calling a method?
Example:
public void MyTestMethod1()
{
string myVar = "Hello World";
MyTestMethod2(myVar);
}
public void MyMethod2(string parm)
{
// do some reflection magic here that detects that this method was called using a variable called 'myVar'
}
...
Hi,
I'm writing an iphone application with JSON and am trying to turn JSON strings into objects (NOT Dictionaries or Arrays).
In Java, thanks to Reflection, I can easily turn JSON into javabean instances like this:
import net.sf.json.JSONObject;
class MyBean {
private String property;
public String getProperty() { return prope...
In python is it possible to run each function inside a class?
EDIT:
What i am trying to do is call of the functions inside a class, collect their return variables and work with that.
...
CustomerValidator: AbstractValidator<Customer>
How might one dynamically instantiate the class above if passed an instance of a Customer??
Similarly if I had:
Cat c = new Cat();
I would want to dynamically invoke the class that implements
AbstractValidator<Cat>
...