Hi,
I'm looking for a way to add members dynamically to an dynamic object. OK, I guess a little clarification is needed...
When you do that :
dynamic foo = new ExpandoObject();
foo.Bar = 42;
The Bar property will be added dynamically at runtime. But the code still refers "statically" to Bar (the name "Bar" is hard-coded)... What if ...
Hello
Is it possible to use getConstructor to obtain the constructor of the class X below?
public class A {
}
public class Y {
}
public class X extends Y {
public X(A a, Y[] yy) {
}
public void someMethod() throws SecurityException, NoSuchMethodException {
Class<? extends Y> clazz = X.class;
Constructor<...
I load dynamically an external class from my eclipse rcp application with urlClassLoader. The invoke()-method returns an Object of self-defined Type.
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader cl = URLClassLoader.newInstance( url);
Thread.currentThread().setContextClassLoader(cl);
S...
Hi again, now i have a more theorical question related with events and reflection. The question is: "Is or isn't possible to get the field of type delegate associated with an event via EventInfo?"
Basically when you define an event (implicitly), the compiler adds a private delegate field to your class (the delegate is of the same type o...
How do i check if a Type is a struct? IsClass worked perfectly then my reflection stop behaving as i expected when i change the class to the struct. How do i check if its a struct? -edit- i need to check for class/structs. Nothing else, i cant match longs, ints, etc by accident. DateTime may be ok i am using this to search a Attribute/Fi...
is this not safe for the class, why is reflection given such power? is this anti-pattern?
...
Hi, I wanna get the value of a private member, so I wrote the following:
var f = e.
GetType().
GetFields(System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.DeclaredOnly)[0];
object o = f.FieldType.GetProperty("Ro...
I want to know if a function is defined for an instance of a class
class c(object):
def func(self): pass
cc = c()
>>> is_function_defined_for_instance(cc,'func')
True
>>> is_function_defined_for_instance(cc,'cnuf')
False
my cleanest attempts at the function is:
def is_function_defined_for_instance(instance,function):
return call...
Hello,
If I have a class instance, containing several included modules, can I dynamically un-include a specific module (In order to replace it)?
Thanks.
...
Hi,
i'm using linq. All my queries looks like var query = dc.GetTable<myType>().
I wish i could choose "myType" using a string parameter. I tried to create a Type object using reflection, but the compiler doesn't recognize Type objects as class definitions.
Any suggestions?
Thanks
...
Hi, i've got some C# code like this:
string fieldName = ...
string value = ...
if (fieldName == "a") a = value;
if (fieldName == "b") b = value;
if (fieldName == "c") c = value;
if (fieldName == "d") d = value;
...
I want something like this:
string fieldName = ...
string value = ...
SetMyInstanceVariable(fieldName, value);
...
I...
In my reflection code i hit a problem with my generic section of code. Specifically when i use a string.
var oVal = (object)"Test";
var oType = oVal.GetType();
var sz = Activator.CreateInstance(oType, oVal);
Exception
An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll
Addi...
In our application we have number of AggregatorTypes (idea copied from SQL Server)
i.e. MinAggregator MaxAggregator, CountAggregator, And SumAggregator.
Now I should check if Aggregator supports type of provided values. For Count it is not important. For Max and Min I use checking for IComparable.
But what to use for SUM?
I tried Conve...
Hello,
Sample of code:
public class Foo
{
public class Bar
{
public void printMesg(String body)
{
System.out.println(body);
}
}
public static void main(String[] args)
{
// Creating new instance of 'Bar' using Class.forname - how?
}
}
Is it possible to cr...
I understand that you can create a new class with parameters from a string with the following construct:
Class<? extends Base> newClass = (Class<? extends Base>)Class.forName(className);
Constructor<? extends Base> c = newClass.getConstructor(new Class[] {Manager.class, Integer.TYPE});
Base a = c.newInstance(new Object[] {this, new Inte...
I have a DLL. from which I would like to get the app's name. The following code, called from the DLL, returns the DLL's full name:
string assemblyFullUncPath =
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
...so it isn't quite what I'm after. I could add an Assembly parameter, but I'd prefer not to. Is it ...
Is it possible to invoke the no modifier method in a superclass through Java reflection?
...
this code outputs "out value".
class P
{
public static void Main()
{
string arg = null;
try
{
Method(out arg);
}
catch
{
}
Console.WriteLine(arg);
}
public static void Method(out string arg)
{
arg = "out value";
throw new Exception();
}
}
but this one doesn't.
class P
{
publ...
Hi,
I have a FindAll method on my DataAccessLayer which looks like this:
public FindResult<T> FindAll<T>() where T : Entity, new()
and a client code that has a Type[] array which it needs to use to iteratively call the FindAll method with like this:
foreach (var type in typeArray)
{
var result = DataAccessLayer.FindAll<type>...
I have to loop through all the properties in a few classes and check any nullable properties to see if they have a value. How do I cast the value returned from propertyInfo.GetValue() to a generic nullable type so that I can check the HasValue property?
Code snipped for brevity:
foreach (PropertyInfo propInfo in this.GetType().GetProp...