Given an App Domain, there are many different locations that Fusion (the .Net assembly loader) will probe for a given assembly. Obviously, we take this functionality for granted and, since the probing appears to be embedded within the .Net runtime (Assembly._nLoad internal method seems to be the entry-point when Reflect-Loading - and I ...
I would like to assign a value in a class property dynamically (that is referring to it using a variable).
#Something like:
setPropValue($obj, $propName, $value);
...
How can I find out through reflection what is the string name of the method?
For example given:
class Car{
public void getFoo(){
}
}
I want to get the string "getFoo", something like the following:
Car.getFoo.toString() == "getFoo" // TRUE
...
Hi
Im compiling some code at runtime then loading the assembly into the current appdomain, however when i then try to do Type.GetType it cant find the type...
Here is how i compile the code...
public static Assembly CompileCode(string code)
{
Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider();
...
My code can see the non-public members, but not the public ones. Why?
FieldInfo[] publicFieldInfos =
t.GetFields(BindingFlags.Instance | BindingFlags.Public);
is returning nothing.
Note: I'm trying to get at the properties on the abstract class as well as
the concrete class. (And read the attributes as well).
The MSDN example w...
Given an assembly that contains
namespace Foo{public class Bar;}
How could I create an Action<Foo.Bar> from another assembly without referencing the first assembly at compile time?
...
Hi,
I have a class with 3 List collections like the following.
I am trying to have a logic which will iterate through the object's "collection"
properties and do some operation using the data stored in those collections.
I am just wondering if there is an easy way of doing it using foreach.
thanks
public class SampleChartData
{...
Inspired by an SO question. The Attribute class has several overloads for the IsDefined() method. Covered are attributes applied to Assembly, Module, MemberInfo, ParameterInfo. The MemberInfo overload covers PropertyInfo, FieldInfo, EventInfo, MethodInfo, ConstructorInfo.
That takes care of most of the AttributeTargets. Except for on...
I am writing a library that generates derived classes of abstract classes dynamically at runtime. The constructor of the derived class needs a MethodInfo of the base class constructor so that it can invoke it. However, for some reason Type.GetConstructor() returns null. For example:
abstract class Test
{
public abstract void F();
}
...
After generating a type dynamically and calling TypeBuilder.CreateType, I want to create a delegate that points to a method in the new type. But if I use code like
loadedType = typeBuilder.CreateType();
myDelegate = (MyDelegate)Delegate.CreateDelegate(
typeof(MyDelegate), methodBuilder);
Reusing the m...
Is there a way to automatically insert code into a method?
I have the following typical field with a getter and setter and I would like to insert the indicated code into the setter method that records if the field was modified as well to insert the indicated "isFirstNameModified" field to also track if the field was modified or not.
p...
For complete separation/decoupling, I've implemented a DAL in an assebly that is simply being copied over via post-build event to the website BIN folder. The website then on Application Start loads that assembly via System.Reflection.Assembly.LoadFile. Again, using reflection, I construct a couple of instances from classes in that assemb...
I have the following class
public class MyClass<T> {
public Class<T> getDomainClass() {
GET THE CLASS OF T
}
}
I've googled this problem and all the answers I could find told me to use getGenericSuperClass(), but the problem of this method is that I must have a second class that extends MyClass and I don't want to do...
I'm looking for a way to modify properties on a dynamic C# 4.0 object with the name of the property known only at runtime.
Is there a way to do something like (ExpandoObject is just used as an example, this could be any class that implements IDynamicMetaObjectProvider):
string key = "TestKey";
dynamic e = new ExpandoObject();
e[key] = ...
I was surprised to learn that "ref" and "out" parameters are not marked by a special attribute, despite the existence of ParameterInfo.IsOut, ParameterInfo.IsIn (both of which are always false as far as I can see), ParameterAttributes.In and ParameterAttributes.Out. Instead, "ref" parameters are actually represented by a special kind of ...
Does code like this (potentially) violate the iPhone Developer License Agreement?
Class clazz = NSClassFromString(@"WNEntity");
id entity = [clazz entityWithImage:@"Icon.png"];
SEL setPositionSelector = NSSelectorFromString(@"setPosition:");
objc_msgSend(entity, setPositionSelector, CGPointMake(200, 100));
I'm working on code that dyn...
let's say I have 2 classes like this:
public class Foo
{
[Required]
public string Name {get;set;}
}
public class Bar
{
// put here [Required] at run-time
public string Name {get;set;}
}
var foo = new Foo();
var bar = new Bar();
//copy the required from foo to bar
is it possible to copy the attributes from foo to bar at run-time ?
...
This has me pooped, is there any reason the following:
public abstract class aExtension
{
public abstract bool LoadExtension(Constants c); // method required in inherit
public abstract string AppliesToModule // property required in inherit
{
get;
}
public abstract string ExtensionName // property required in ...
Possible Duplicate:
Calling a method named string at runtime in Java and C
I need to be able to call a function, but the function name is stored in a variable, is this possible. e.g:
public void foo ()
{
//code here
}
public void bar ()
{
//code here
}
String functionName = "foo";
// i need to call the function based ...
say, I have the following:
trait SomeTrait {
def someMethod: String;
}
object SomeObject extends SomeTrait {
def someMethod = "something";
}
I would like to call "someMethod" using reflection as I have the object name as a String.
Something like:
val objectName = "SomeObject"
val someTrait:SomeTrait = ???.asInstanceOf[SomeTr...